Link to home
Create AccountLog in
Avatar of Scott Palmer
Scott PalmerFlag for United States of America

asked on

Assign a value to a combo box

I am using Access 2002 and I need to assign a value to a combo box.  The value I want to assign is in the value list for the combo box.  I have a locked text box that either displays Yes or No.  On opening the form I wanto be able to do this

If txtAltAddress.Value = "No" Then
     cmbUseAltAddress.Value = No
End If

But when I try to open the form with this code I get an error message saying I can't assign a value to this object.  Is there any way to change the value?

Thanks,
Scott

Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

What is the Row Source for your combo box?

What is the Control Source for your combo box?

mx
Avatar of Scott Palmer

ASKER

The value I am basing the decision on is the text in the txtaltaddress.value and I would like to keep it that if I can.

Are you saying to do something like this I would need to access the table(source)?

The source is tblAltAddress and the rowsource is AltAddress.
"rowsource is AltAddress."

ok ... good.

Now, what is the Control Source of the combo box ... ie, then name of the Field in tblAltAddress  - assuming that 'tblAltAddress' is the Record Source for your form?

Does your form have a table ('tblAltAddress' ? ) or a query for the Record Source?

mx
The field name in the source (tblAltAddress) is UseAltAddress.  I am using a query (qryEdit) to access the table (tblAltAddress) and the name of the field in qryEdit is also UseAltAddress.

In this line:

     cmbUseAltAddress.Value = No

What is No? Is it a variable? A field? I guess it's a non-declared variable, which would thus be "Empty", and gets converted to an empty string "". Did you mean

     cmbUseAltAddress.Value = 0   ' e.g. False
     cmbUseAltAddress.Value = "No"
     cmbUseAltAddress.Value = Null

General Advice: Always have "Option Explicit" at the top of each module, and use "debug / compile" before running your code.

Also, form open may be too early for what you want. Try to use Form_Current instead. Then you are sure there is a value in txtAltAddress

Cheers!
(°v°)
ASKER CERTIFIED SOLUTION
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Also ...as HF pointed out ...

 cmbUseAltAddress.Value = No

You cannot just have 'No' unless you have defined No as variable somewhere. OR ... again, as HF says ... it would need to be

False  (ie not True meaning No)
Null
"No"   (a string literal)

mx
DatabaseMX, I just decided to do what I think you were alluding to earlier and changed the value in the query (which is updatable) and not the form and it worked.

Thanks,
Scott
OK Scooter ... whatever it takes ... we got there.

thanks ...

mx
Good point about dirtying the record, mx. You had already established it was a bound control; I should have noticed.
(°v°)
LOL ...and I am **almost** over that Choose function snafu :-)

Besides, you can't notice everything,  where would you put it !!!

mx