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

sql to select a record from query 1

Status
Not open for further replies.

paulminne

Programmer
Nov 27, 2002
80
AU
Hi,

I have a form with a combo box on it. When a name from the combo box is selected I want to display the related records from a query in a report, however I am getting an error when running the code. The error states "Syntax error (missing operator) in query expression '[consultant]=Paul'."

The code looks like this:

*************************
Private Sub cmdPrint_Click()

Dim strInput As String
Dim db As Database
Dim rs As ADODB.Recordset
Dim strSQL As String
Dim stLink As String
Dim strName As String

stDocName = "WeeklyJobs"

strName = cboConsultant.Column(0)

Set rs = New ADODB.Recordset

rs.ActiveConnection = CurrentProject.Connection

stLink = "[consultant]= " & strName

strSQL = "SELECT * FROM JobsBooked2 WHERE " & _
stLink

Set db = CurrentDb

rs.Open strSQL <----ERROR OCCURS HERE

DoCmd.OpenReport stDocName, acViewNormal, , stLink

DoCmd.Close acReport, stDocName

Set rs = Nothing
Set db = Nothing

End Sub
***********************************

The consultant field is just a text field

Regards,

- Paul
 
Hi there

You should have quotes around the consultant name

change
stLink = &quot;[consultant]= &quot; & strName

to
stLink = &quot;[consultant]= '&quot; & strName & &quot;'&quot;

Transcend
[gorgeous]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top