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

Returning matching records when data is text

Status
Not open for further replies.

cschmid

Technical User
Apr 1, 2002
8
0
0
US
I found this example in a previous thread in which the user enters a number in a textbox (PartNo) and the code returns the matching recordset from selected fields in the same table. Code works when PartNo is a numeric data type but in my case PartNo is a text data type (example: D1345). How would I get this to work with a text data type? Thanks in advance,

Private Sub txtPartNo_AfterUpdate()
Dim rst As DAO.Recordset
Dim sql As String

sql = "Select * From Contents Where PartNo =" & Me!txtPartNo

Set rst = CurrentDb.OpenRecordset(sql, dbOpenDynaset)
If rst.EOF = True And rst.BOF = True Then
Call MsgBox("The Part Number you entered does not exist")
Else
Me!txtPartName = rst!PartName
Me!txtPieces = rst!Pieces
Me!txtPrice = rst!Price
End If

Set rst = Nothing

End Sub

Set rst = Nothing
End Sub
 
Figured it out.
sql = "Select * From Contents Where PartNo= """ & Me!txtPartNo & """"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top