
newbie question concerning if-then-else
If you insist on using a hard-coded if then statement, the syntax would be:
'Assuming the State is stored in the first column of the combo box
If Me!cmbBox.column(0) = "CA" then
Me!Country = "USA"
elseif Me!cmbBox.column(0) = "CT" then
Me!Country = "USA"
'more elseif statements here
endif
However, what I would recommend doing is the following:
1. Create a table with two fields. "State", and "Country"
2. Write a function to return the country based on the state.
3. The function would look like this: (Keep in mind, the following
function will work faster if set the rs variable to a query that only pulls
the State you are looking for.)
Public Function GetCountry(MyState as string) as string
'Write your own error code
Dim rs as recordset
Set rs = currentdb.openrecordset("<<table name here")
'Check to make sure records exist
If not rs.recordcount > 0 then
rs.close
'Put error code here
endif
rs.movefirst
do until rs.eof
if rs!State = MyState then
GetCountry = rs!Country
rs.close
exit function
endif
rs.movenext
Loop
rs.close
End Function
4. Now, in the AfterUpdate event of the State combo box, you will put the
following code
Me!Country = GetCountry(Me!cmboBoxState.column(0).text)
--
Paul Brower
"I Love DSL!"
Quote:
>I have been racking my brains on how to get the syntax right for an
>if-then-else statement
>I have a combo box on a form where the user chooses a province or state. In
>the next box they fill in the country.
>I want the country box to automatically enter the proper country based on
>the province or state chosen.
>I assume and if statement was the best route to take...maybe I am wrong?
>If not what is the syntax to make it work? I keep getting errors.
>Thanks
>Todd