Data Type mismatch in criteria expression

N

neeley

I have code that returns the above message. Can someone
tell me what is incorrect?

Dim db as databse
dim rs as recordset
set db = CurrentDb
Set rs = db.OpenRecordset("SELECT * FROM Facility where
[Facility]![fac_Code] = " & Me!fac_Code)
If Not rs.EOF THEN
Me!fac_FacilityType = rs!fac_FacilityType
End If
rs.Close
db.Close
Set rs= Nothing
set db = Nothing
End Sub

The error occurs at the set rs= db.OpenRecordset line.

Thanks for any help.
 
S

Scott N. Weber

try:
Set rs = db.OpenRecordset("SELECT * FROM Facility where
[Facility]![fac_Code] = '" & Me!fac_Code & "'")

I added a concatenation for the Me![FAC_CODE] to include single quote around
it.
 
J

John Vinson

I have code that returns the above message. Can someone
tell me what is incorrect?

I'm guessing that FAC_Code is a field of Text type. If so you need the
syntactically required quotemarks:

Set rs = db.OpenRecordset("SELECT * FROM Facility where
[Facility]![fac_Code] = '" & Me!fac_Code & "'")
 
N

neeley

The single quote worked. Thank you!
-----Original Message-----
try:
Set rs = db.OpenRecordset("SELECT * FROM Facility where
[Facility]![fac_Code] = '" & Me!fac_Code & "'")

I added a concatenation for the Me![FAC_CODE] to include single quote around
it.


--
Scott N. Weber, MCP
http://www.AccessYourBiz.Com
Customizable Accounting Software
Written with Microsoft Access

I have code that returns the above message. Can someone
tell me what is incorrect?

Dim db as databse
dim rs as recordset
set db = CurrentDb
Set rs = db.OpenRecordset("SELECT * FROM Facility where
[Facility]![fac_Code] = " & Me!fac_Code)
If Not rs.EOF THEN
Me!fac_FacilityType = rs!fac_FacilityType
End If
rs.Close
db.Close
Set rs= Nothing
set db = Nothing
End Sub

The error occurs at the set rs= db.OpenRecordset line.

Thanks for any help.


.
 
N

neeley

Thanks for the help. The single quote was the missing
piece.
-----Original Message-----
I have code that returns the above message. Can someone
tell me what is incorrect?

I'm guessing that FAC_Code is a field of Text type. If so you need the
syntactically required quotemarks:

Set rs = db.OpenRecordset("SELECT * FROM Facility where
[Facility]![fac_Code] = '" & Me!fac_Code & "'")



.
 

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