Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AutoNumber Lookup?

Status
Not open for further replies.

BT24

Programmer
Aug 19, 2002
76
CA
Hello there

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.

thanks for the help

BT24
 
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

Exit_cmdOpen_Click:
Exit Sub

Err__cmdOpenClick:
MsgBox Err.Number & " : " & Err.Description
Resume Exit_cmdOpen_Click

End Sub

Tony L
ABQ, NM
 
Hello Tony

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

thanks for the help

BT24
 
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.

Tony L
ABQ, NM
 
Thanks for the help, i figured it out!

Have a nice day

BT24
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top