Open Recordset Using text as criteria.

A

ajbarilla

I have a form with a button that I am trying to use to fill information
about documents. The information about the documents is listed in
"tblDocumentList." The names of the documents are displayed in a
text box that pulls directly from "tblDocumentList." I am including
my code below. When I run the code, I get a syntax error.

searchcrit = Me.DocumentList

Set rstedit = db.OpenRecordset("SELECT * FROM tblDocumentList WHERE
tbldocumentlist.[Document] = " & searchcrit)


I believe the problem is originating from the fact that the search
criteria is text. If i use the code below and search by the ID
number of the documents it works, but not with the document name.

searchcrit = Me.DocumentList

Set rstedit = db.OpenRecordset("SELECT * FROM tblDocumentList WHERE
tbldocumentlist.[ID] = " & searchcrit)

any help would be appreciated.
 
S

Svetlana

You need to put quotes
Set rstedit = db.OpenRecordset("SELECT * FROM tblDocumentList WHERE
tbldocumentlist.[Document] = '" & searchcrit & "'")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top