What i would like to do is to have a form that will find certain records in another form by searching by the Autonumber. If this dosn't make any sense let me know i will try to explain it differently.
I've done a bit of work similar to what you are looking for.
I create a form that is not bound to anything (frm1), then create a text box on that form (txtBox1) that I use to input the number to be looked up. You can set this to be referencing a drop down list and define it, so the autonumbers can be typed in or selected by the drop down.
Then I add a command button to the form (cmdOpen) that opens the new form (frm2) with items that I want to view related to that number (autoNum). I place this code on that command button:
Private Sub cmdOpen_Click()
On Error GoTo Err_cmdOpen_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "frm2"
'Closes the form frm1 if there is no input,
'else it opens the form frm2.
If IsNull([txtBox1]) Then
DoCmd.Close acForm, "frm1", acSaveNo
Else
stLinkCriteria = "[autoNum]=" & Forms![frm1]![txtBox1]
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If
Thanks for the help. I imputed the information that you gave me but it didnt work, i changed all the names so that they matched what i have. The button when its clicked on dosnt do anything. i imput the # that i want and then click on the button but i get nothing
After posting the code, did you check your form in design view to make certain the code is connected to the form? Go to the command button (or whatever item you are using to open up the form or report), do a right-click and select "Properties". From there select the "Event" tab. Check to see what is listed under "On click". If that is blank, click on the box, then click on the ellipses box to the right that appears. Select the "Code Builder". This should bring up the code and the specific place where the code was written. You can then close the code builder. Save the form, and test it again.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.