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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search box 1

Status
Not open for further replies.

neilmcmor

Technical User
Joined
Aug 9, 2007
Messages
30
Location
GB
I would like to have a search box/form activate from a form when a button is clicked. The search box would clear the main form and fill it with the record that gets entered into the search box. I have tried the following code but does not work. The main form is called [Prisoner_Details] and the field I am using to search on is [Spin]. when this code is used on the button click of the main form a box appears but when I enter data in to its search field I get the message "invalid use of NUll".

Private Sub cmdFind_Click()
On Error GoTo Err_cmdFind_Click

Dim answer As String
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Prisoner_Details"

answer = InputBox("Enter the Spin Number you wish to search for", "Find on Spin")

stLinkCriteria = "[Spin]= answer

DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdFind_Click:
Exit Sub
Err_cmdFind_Click:
MsgBox Err.Description
Resume Exit_cmdFind_Click
End Sub
 
What data is represented by the animated smiley?

I wondered why the baseball was getting bigger.
Then it hit me.
 
The animated smiley has appeared in place of Spin with [ ] around it. that line should read stLinkCriteria = spin = answer
Again I have removed the [ ] from spin as the site seems to think its a smiley
 
What about this ?
Code:
stDocName = "Prisoner_Details"
answer = InputBox("Enter the Spin Number you wish to search for", "Find on Spin")
If Trim(answer & "") <> "" Then
  stLinkCriteria = "spin='" & answer & "'"
  DoCmd.OpenForm stDocName, , , stLinkCriteria
End If
If spin is defined as numeric then get rid of the single quotes.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks. It is numeric. Tried the code now I am getting the following Compile error Label not found. And the VBA Editor opens and highlights 'Resume Exit_cmdFind_Click' at the end of the sub
 
Thanks for the code. I removed all reference to the error click and it works great. Was I correct to do that?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top