Problem passing parameter to report [DoCmd]

Elfman

Registered User.
Local time
Today, 11:45
Joined
Aug 16, 2007
Messages
27
Hi All,

Here's what I've got so far:

- A form with several combo boxes with filed that the suer can choose to filter a report by.

- Each Combo Box has a button beside it with has the code behind it.

- I have managed to get the code the work for some but it won't for other

Example :
---------

DoCmd.OpenReport "rpt_PDP_data", acViewPreview, , "[pref_1]= " & Me.pref_1 (This one works)


DoCmd.OpenReport "rpt_PDP_data", acViewPreview, , "[Name]= " & Me.CboName (This one doesn’t)

It gives an error message saying :

Syntax error (missing operator) in query expression

Can anyone see what i might be doing wrong??

Thanks in advance

-Elfman
 
How many columns does the combo box have? Step through the code and hover the mouse over the 'Me.CboName' and see what it is returning...

:)
Ken
 
Last edited:
Hi Elfman,

Everything looks ok to me from the info you have given, provided that [name] exists in the record source of your report being opened and [CboName] exists in the form where the code is being run from.

If you dont find any fault post a copy of your DB on here.

Garry
 
It's set up as col count = 2

Name and CboName are def right.

mmm a bit stumped am I
 
Is CboName a string in which case Try

DoCmd.OpenReport "rpt_PDP_data", acViewPreview, , "[Name]= '" & Me.CboName & "'"
 
It's set up as col count = 2

Name and CboName are def right.

mmm a bit stumped am I

Is the Name you want in col 1 or col 2 of CboName? Because your reference will I think return whatever is in the bound column.
 
Well I changed the col count to one cos that’s all I have still same problem. I tried putting the & "" at the end but no good I'm afraid,


The actual error message says
Syntax error (missing operator) in query expression '([Name]= <The persons name>)'

and finds the right name
 
DoCmd.OpenReport "rpt_PDP_data", acViewPreview, , "[Name]= '" & Me.CboName & "'"
 
Still no luck I'm afraid still saying syntax error.

Quick Q do i need any special setup on my form to pass parameters ??
 
Oh wait cancel that seems to have done it but now it's telling me

Data type mismatch in criteria expression

hummmmm don't like this DB

By the way thanks for all your help on the other error message
 
Also, you should change your column name "NAME" to something else because NAME is an Access Reserved word and can honk things up for you if you use it.
 
If you post the db someone will probably spot what the solution is there and then.
 
Try:

DoCmd.OpenReport "rpt_PDP_data", acViewPreview, , "[Name]= '" & Me.CboName.Column(0) & "'"

The Column number is the column of the info that you want to use. (Columns start from 0, not 1)


Sorry, I missed that that solution was already used
 

Users who are viewing this thread

Back
Top Bottom