how to send a parameter to a report using vba

godknow

Registered User.
Local time
Today, 15:52
Joined
Jun 26, 2012
Messages
15
i am trying to put a button and clicking it will send the recordsource as parameter to the report. the report is generated using query which needs userid as parameter.

please guide me through VBA code for it.

here is what i have so far

DoCmd.OpenReport " USERReport ", acViewPreview, , " UserID= '" & Me.RecordSource & "'"
it still pompts me for a parameter

thanks
 
The recordsource can't be set as a parameter.

If you are on a record and the field on the form is UserID also (and is not text):

Code:
DoCmd.OpenReport "USERReport", acViewPreview, , "UserID= " & Me.UserID

If it is text:

Code:
DoCmd.OpenReport "USERReport", acViewPreview, , "UserID= " & Chr(34) & Me.UserID & Chr(34)

And my code also removed spaces you had which can't be there.
 
You wouldn't specify the entire record source there, you'd specify the user ID, like

Me.UserID

In case the field isn't text:

i tried that, but still it is not working.
Code:
DoCmd.OpenReport "USERReport", acViewPreview, , "[UserID] = " & Me.UserID

Image one is Form
Image two is Asking for parameter to show the report after click the button.
Image three is the query that will be used by report.

Plzz help me with this problem. i really need this option.
 

Attachments

  • 1.PNG
    1.PNG
    15.3 KB · Views: 146
  • 2.PNG
    2.PNG
    20.5 KB · Views: 149
Last edited:
The parameter prompt comes from the criteria in your query.
 

Users who are viewing this thread

Back
Top Bottom