Searching for a record based on a text box value

N

Nick.Korynski

I am trying to use the openforms command to open a form on a certain
record based on user input from a text box. The user enters a value
that is in this format: xx-xxxx where x is any integer or letter. For
some reason, when I put this into the where condition in the openforms
command, when executed, it is not finding the record properly. Does
this have something to do with the - or should it work properly with
the dash? Here is my code:

Option Compare Database
Public InputTailNumber As String
Private Sub Command2_Click()
DoCmd.OpenForm "Images", , , "TailNumber ='" & InputTailNumber &
"'"
End Sub
Public Sub SearchByTailNumber_Change()
InputTailNumber = Me.SearchByTailNumber.Text
End Sub

Thanks,

Nick
 
N

Nick.Korynski

I am getting an error that I can't reference the control because the
control doesn't have focus. Is there a way to set the focus to the
control in VB? Thanks.
 
R

Ruel Cespedes via AccessMonster.com

You are not referencing the textbox Object properly.

Lets say "Form1" is the form name where the text field resides. Lets also
say that Form2 is the form that is opened from Form1 Command Button. Lastly,
lets call the TextField on Form1 "Text1".

When you click on the Command Button your code looks like this:

Private Sub CommandButton_Click()

DoCmd.OpenForm "Images", , , "TailNumber = ' " & Forms![Form1]![Text1] & "
' "

End Sub




Ruel
 

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