combobox list default

F

ferde

I have a form that generates data to one table. I would like my combobox
list on the form to default to "N/A" when the form opens but when I set the
default value on the property box in design mode to "N/A" which is the first
entry on the list or row source ... it doesnt work. Can someone tell me what
I am doing wrong please?

Access 2003
Control Name ClinicalTrial
Row Source "N/A";"yes";"no"
Row source type value list
Default value "N/A"
 
K

Ken Sheridan

You'll perhaps find it more reliable to do it in code in the form's open
event procedure:

Me.ClinicalTrial.DefaultValue = """N/A"""

Note the pairs of contiguous quotes characters within the string expression.
These are interpreted as literal quotes characters. the DefaultValue
property is always a string expression regardless of the data type involved.
As yours is text it probably won't make any difference in this case, but it
can sometimes be crucial when you might not expect it (dates particularly) so
its best to do it the right way regardless of whether its absolutely
necessary/.

Ken Sheridan
Stafford, England
 
F

ferde

Thank you Ken for the reply. I tried your suggestion but I never used this
event form before and so I'm doing something really silly I'm sure. Can you
provide me with a little more direction. Thank you so much. Deb


I am in my form in design view and right click on the control to go to
properties and EVENT tab and typed in the following;
 
K

Ken Sheridan

Deb:

I think what you've done is enter the code directly in the properties sheet
– it’s a common mistake. If you are unfamiliar with entering code in event
procedures this is how its done:

In form design view firstly delete the code you entered in the control's On
Enter event property. Then select the form by clicking on the small black
square at its top left corner. Open its properties sheet if its not already
open. Then select the 'On Open' event property in the properties sheet.
Delete any code you've entered in it. Click on the 'build' button; that's
the one on the right with 3 dots. Select 'Code Builder' in the dialogue, and
click OK. The VBA window will open at the event procedure with the first and
last lines already in place. Enter the line of code between these two
existing lines. Save the form and then open it in normal form view to try it
out.

Also I notice that you've put only two quotes characters either side of the
N/A. If you look at my original reply you'll see that it has three -
"""N/A""". The outermost ones are the delimiting characters for the string
expression as a whole, and the two inner sets of two contiguous quotes
characters are how a literal quotes character is included within a string
expression – when Access sees two together like this within an outer set of
quotes characters it interprets each inner pair as a single literal quotes
character.

Ken Sheridan
Stafford, England
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top