help with If then statemant

tommy_mo

Registered User.
Local time
Today, 01:27
Joined
Oct 5, 2006
Messages
42
Hello-

I was wondering if someone would be willing to help me put together code for a form button. I want the button to go to a record that is typed into a text box based on the key field of a query. If there is no key that matches then I would like to have a message say someting like "record does not exist" Below is my code without any message for entries that do not match the text box. Any ideas???

Private Sub Command2_Click()
On Error GoTo error_msg

Me.id_list.Requery

DoCmd.OpenForm "mainsubform", acNormal, , "[key] = " & Me.id_form_text
Exit Sub

error_msg:
MsgBox "Record does not exist."
Exit Sub


End Sub
 
I wouldn't do it that way. I'd use a combo box linked to the key field so that users can only select existing entries. It stops users getting spelling wrong and makes it more user friendly.
 
Would that work if there are 15,000 keys? -Tom
 
Yes, and I agree with the recommendation. As the user begins to type in the combo, it will drop to that point in the data. They would not have to scroll all the way to their selection.
 
awesome. It works great! I just had to set "limit to list" to yes and now I don't need to create a message for entries that don't exist! Thanks. I'm learning more every day.
 

Users who are viewing this thread

Back
Top Bottom