Form Search box HELP? (1 Viewer)

DanK

New member
Local time
Today, 06:31
Joined
Oct 11, 2017
Messages
4
Hi all,
I'm sure this will be a dead easy fix for this forum.. but its had me :banghead: for hours..
I have a database to control lending of power tools, i based it around a lending library and have built a form where i want to add a search box so that a power tool can be scanned on its unique barcode to find the relevant record and the check out/in procedure can then be completed.
Im getting an invalid argument error 3001
I've built the code around the search button as follows. ive highlighted what is showing as error in red.

Private Sub Find_Click()
If IsNull(Search) = False Then
Me.Recordset.FindFirst '[Item]=' & Search
Me!Search = Null
If Me.Recordset.NoMatch Then
MsgBox "No Record Found", vbOKOnly + vbInformation, "Sorry"
Me!Search = Null
End If
End If
End Sub

I have created a text box and named it search, ive also bound it to Item in the dropdown menu (but this makes the box show an item number based on the record selected at the bottom- i seem unable to make it a blank search return system) and have built the code as above. i have created a command button called Find
I have Item as a column in table Assets so don't know if i need to fit this in somewhere?
Is anyone able to help me out? if needed i can email the workbook database.
Many thanks in advance...
Dan
 

Gasman

Enthusiastic Amateur
Local time
Today, 14:31
Joined
Sep 21, 2011
Messages
14,217
I think that should be
Code:
[COLOR=Red]Me.Recordset.FindFirst "[Item]= " & Me.Search[/COLOR]
if ItemID is numeric. If not
Code:
[COLOR=Red]Me.Recordset.FindFirst "[Item]= '" & Me.Search & "'" & Chr(34)[/COLOR]
if character

I use the CHR(34) as can never get the syntax correct for the last " to end the string.
HTH
 

DanK

New member
Local time
Today, 06:31
Joined
Oct 11, 2017
Messages
4
Thanks Gasman, i tried that but unfortunately not worked either.
Its a numerical individual item code we use, im getting the same error altering the code to how you would use it..
Thanks for your input, any other ideas?
Dan
 

Minty

AWF VIP
Local time
Today, 14:31
Joined
Jul 26, 2013
Messages
10,367
Your syntax is off as per Gasman's post, I normally use a recordset clone for this - try

Code:
Private Sub Find_Click()

       Dim rs   As Recordset
	
	    If Not IsNull(Me.Search) Then
	        Set rs = Me.RecordsetClone
	        rs.FindFirst "[Item] = " & Me.Search
	        If Not rs.NoMatch Then
	            Me.Bookmark = rs.Bookmark
	        Else
	        	MsgBox "No Record Found", vbOKOnly + vbInformation, "Sorry"
	        End If
	        rs.Close
                Set rs = Nothing
	    End If
      
      Me.Search = Null
    
End Sub
 

DanK

New member
Local time
Today, 06:31
Joined
Oct 11, 2017
Messages
4
Your syntax is off as per Gasman's post, I normally use a recordset clone for this - try

Code:
Private Sub Find_Click()

       Dim rs   As Recordset
	
	    If Not IsNull(Me.Search) Then
	        Set rs = Me.RecordsetClone
	        rs.FindFirst "[Item] = " & Me.Search
	        If Not rs.NoMatch Then
	            Me.Bookmark = rs.Bookmark
	        Else
	        	MsgBox "No Record Found", vbOKOnly + vbInformation, "Sorry"
	        End If
	        rs.Close
                Set rs = Nothing
	    End If
      
      Me.Search = Null
    
End Sub

Hi Minty,
I've updated to match your coding and my original error has gone but has been replaced by Compile error: Argument not optional
can you offer any assistance as to what this means in relation to your code?
 

Gasman

Enthusiastic Amateur
Local time
Today, 14:31
Joined
Sep 21, 2011
Messages
14,217
Thanks Gasman, i tried that but unfortunately not worked either.
Its a numerical individual item code we use, im getting the same error altering the code to how you would use it..
Thanks for your input, any other ideas?
Dan

Strange?
I had this in one of my databases which worked, before I moved to an Emulated Split Form. It ran from the subform.

Code:
Me.Parent.Recordset.FindFirst "ID=" & Me.ID

Edit: Just noticed I did not use the [], wonder if that is the problem?
 
Last edited:

Minty

AWF VIP
Local time
Today, 14:31
Joined
Jul 26, 2013
Messages
10,367
Very odd - add the following line in red
Code:
 Dim rs   As Recordset
	[COLOR="Red"]    msgbox"Your are searching for this: " & Me.Search & " : "[/COLOR]
	    If Not IsNull(Me.Search) Then
	        Set rs = Me.RecordsetClone
	        rs.FindFirst "[Item] = " & Me.Search
	        If Not rs.NoMatch Then
	            Me.Bookmark = rs.Bookmark
	        Else
	        	MsgBox "No Record Found", vbOKOnly + vbInformation, "Sorry"
	        End If
	        rs.Close
                Set rs = Nothing
	    End If
      
      Me.Search = Null

Oh and which line is the error highlighting?
 

Users who are viewing this thread

Top Bottom