views:

79

answers:

2

For instance, I have a query which takes as a parameter the text property of a drop-down box [DDB1] of Form1. How do I reference the property? My stumbling around google has suggested that it should be something along the lines of Forms![Form1]![DDB1].text But I have been unable to find a definitive syntax for such references.

Any ideas?

Semi- OT - the Access2003 help, which contains links to a lot of Microsoft web pages, returns a lot of 404s when trying to load them. Is this just coincidence? Or end-of-lifing by stealth?'

+1  A: 

To have a query reference a combo box on a form, use this syntax:

Forms!MyForm!MyComboBox

This will retrieve the selected value property of the combo box (the value of the first column, if it is a multi-column combo box).

If you want the selected value of a different column in the combo box, it is:

Forms!MyForm!MyComboBox.column(n)

Unlike most numeric indexes in VBA, n is zero based (the second column is 1).

To reference the text property, the combo box must have the focus.

The help file is apparently suffering from link rot. Here are some links in MSDN to use:

Access 2003 Programming Reference
http://msdn.microsoft.com/en-us/library/aa167788(office.11).aspx

Access 2003 Language Reference
http://msdn.microsoft.com/en-us/library/aa663079(office.11).aspx

Robert Harvey
If, however the form or control name contains spaces or other special characters, you will need to put [] square brackets around the form or control name.
Tony Toews
A: 

You have in fact multiple ways to refer to a control with MS-Access. In addition to @Robert Harvey proposal, you can also write:

forms(myFormName).controls(myControlName)

Despite what @Robert says, you can access most properties of a control without setting the focus on it. One important exception is the ".text" property, which refer to the text appearing in the control, and where the focus must be set to the corresponding control.

Most of the time, the .text property is equal to the .value property, that can be accessed without setting focus on the control.

Thus, this property is useful only for controls of the combobox or listbox type, where the bound column (that gives the .value property) differs from the displayed column (giving the .text property).

Philippe Grondier