Code error question

G

Guest

Hello there,
I am using Access 2003 (11.5614.5606) with Microsoft XP Professional.
I have gone over and over the strsql2 string but cannot figure out what is
wrong, see error below.

This sub is intended to use the selected combo box Item to filter by
selected customer name,
in which the output will be used to create a chart.

Private Sub Combo36_BeforeUpdate(Cancel As Integer)
Dim dbs2 As DAO.Database
Dim qdf2 As DAO.QueryDef
Dim rs2 As Recordset
Dim strsql2 As String

Set dbs2 = CurrentDb
strsql2 = "SELECT * FROM RecyHistory WHERE CompanyName" _
& " = " & Forms![test form]!Combo36 & ";"

Set qdf2 = dbs2.CreateQueryDef("", strsql2) 'runtime error 3075
'missing operator in query expression Company name = TEST'

Set rs2 = qdf2.OpenRecordset

rs2.Close
End Sub


Thank you
Paul
 
J

Jeanette Cunningham

Hi Paul,
assuming company name is a text data type
try it like this-->

strsql2 = "SELECT * FROM RecyHistory " _
& "WHERE CompanyName = """ & Forms![test form]!Combo36 & """"


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 
G

Guest

Thank you Jeanette, it worked perfectly:)

-Paul

Jeanette Cunningham said:
Hi Paul,
assuming company name is a text data type
try it like this-->

strsql2 = "SELECT * FROM RecyHistory " _
& "WHERE CompanyName = """ & Forms![test form]!Combo36 & """"


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia


Hello there,
I am using Access 2003 (11.5614.5606) with Microsoft XP Professional.
I have gone over and over the strsql2 string but cannot figure out what
is wrong, see error below.

This sub is intended to use the selected combo box Item to filter by
selected customer name,
in which the output will be used to create a chart.

Private Sub Combo36_BeforeUpdate(Cancel As Integer)
Dim dbs2 As DAO.Database
Dim qdf2 As DAO.QueryDef
Dim rs2 As Recordset
Dim strsql2 As String

Set dbs2 = CurrentDb
strsql2 = "SELECT * FROM RecyHistory WHERE CompanyName" _
& " = " & Forms![test form]!Combo36 & ";"

Set qdf2 = dbs2.CreateQueryDef("", strsql2) 'runtime error 3075
'missing operator in query expression Company name = TEST'

Set rs2 = qdf2.OpenRecordset

rs2.Close
End Sub


Thank you
Paul
 

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