Select Current Record for Report

D

depawl

I have a combo box on a form with a list of employee names. When the
user selects an employee from this combo box, I want it to open a report
of the selected record with info on the selected employee only.
I have the following code in the After Update event of the combo box:
Dim strDocName As String
Dim strWhere As String
strDocName = "EmployeeReport"
strWhere = "[EMPLOYEENAME]=" & Me!EMPLOYEENAME
DoCmd.OpenReport strDocName, acPreview, , strWhere

But when I run it I get the following error message:
Syntax error (missing operand) in query expression '([EMPLOYEENAME]=
John Doe)'

What am I missing?
Thanks.
 
C

Chris Large

You need quotes around the string. When you enter criteria
in the Query design grid Access puts the quotes around any
text you enter, but from code you must do this yourself.
Change to the following:-

strWhere = "[EMPLOYEENAME]=""" & Me!EMPLOYEENAME & """"

note that you need to doubled the quotes when used inside
other quotes.

hth

Chris
 
D

depawl

OK Thanks Chris.
That took care of the error message. However, the code doesn't seem to
do what I intended it to do. I wanted it to print a report for only the
record that a user selects in a combo box on the form, but the report it
generates seems to be only the first record in the report's underlying
query. I don't seem to be able to get it to print only the record that I
want.
Any ideas?


Chris said:
You need quotes around the string. When you enter criteria
in the Query design grid Access puts the quotes around any
text you enter, but from code you must do this yourself.
Change to the following:-

strWhere = "[EMPLOYEENAME]=""" & Me!EMPLOYEENAME & """"

note that you need to doubled the quotes when used inside
other quotes.

hth

Chris


-----Original Message-----
I have a combo box on a form with a list of employee
names. When the

user selects an employee from this combo box, I want it
to open a report

of the selected record with info on the selected employee

only.


I have the following code in the After Update event of
the combo box:

Dim strDocName As String
Dim strWhere As String
strDocName = "EmployeeReport"
strWhere = "[EMPLOYEENAME]=" & Me!EMPLOYEENAME
DoCmd.OpenReport strDocName, acPreview, , strWhere

But when I run it I get the following error message:
Syntax error (missing operand) in query
expression '([EMPLOYEENAME]=

John Doe)'

What am I missing?
Thanks.

.
 

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