Help with a slight code adjustment

  • Thread starter Thread starter kinetix
  • Start date Start date
K

kinetix

Guest
Hello all,

I'm a bit of a newbie with Visual Basic so bare with me.

I have a command button with the following code to allow me to search through records in a table with the all the information of that table being displayed in a form.

The code works when i search using numberical fields (Unique Product Code being the one below), but not when i want to search text fields.

Private Sub Command21_Click()

' Find the record that matches the control.
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[UPC] = " & Str(Nz(Me![UPC], 0))
If rs.NoMatch = False Then
Me.Bookmark = rs.Bookmark
Else
MsgBox ("Error! - No Record Found")
DoCmd.GoToRecord acActiveDataObject, , acNewRec

End If

End Sub

I'm sure it is a simple question of changing the
' rs.FindFirst "[UPC] = " & Str(Nz(Me![UPC], 0)) '
to make it specific to a text field instead of a numerical one, but as i said im a newbie so all advice would be greatly aprreciated.

Thanks in advance.
 
KineTix,

rs.FindFirst "[UPC] = '" & Nz(Me.[UPC], "") & "'"

Wayne
 

Users who are viewing this thread

Back
Top Bottom