By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,083 Members | 2,237 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,083 IT Pros & Developers. It's quick & easy.

How do I pass a parameter in VB from a form to a query used in OpenReport?

P: n/a
I have the login name on my form, Ulogin. The Report I call with OpenReport (from VB) uses a parameter, ulog, for the query it based upon. I pass Ulogin in a DOcmd.OpenReport using the where clause Ulog = ULogin. My report still prompts me for Ulog. I want to pass the login value to the parameter in the report such that no dialog box is displayed and the report runs automatically. What is the correct syntax for this or do I need to do this differently?
Thank you
Oct 20 '10 #1
Share this Question
Share on Google+
5 Replies


P: n/a
I tried loading the parameter value in the OpenArgs portion of the OpenReport. I checked it in Debug and it was correct. I loaded the correct value into the parameter value in the Open event for the report. Why does the parameter dialog box continue to prompt me for the login name - even though I successfully loaded it in the open event? My VB code said: ulog = Me.OpenArgs. Do I need to load it differently if it is a parameter?
Thank you for your help
Oct 20 '10 #2

ADezii
Expert 5K+
P: 8,623
You can specify the Criteria in the Where Argument of the OpenReport Method, as in:
Expand|Select|Wrap|Line Numbers
  1. Dim strWhere As String
  2.  
  3. strWhere = "[LastName] = '" & Me![txtLastName] & "'"
  4.  
  5. DoCmd.OpenReport "Employees", acViewPreview, , strWhere, acWindowNormal
Oct 22 '10 #3

NeoPa
Expert Mod 15k+
P: 31,419
AJ, if the query the report is run on has a parameter to be entered there is no way to pass that value to it in code.

To use code to provide the filtering the query itself must be redesigned. The query would be designed to view all records, then the opening would include a filter specification (actually called the WhereCondition parameter of the OpenReport() method) that ensured only the selected record was shown. Does that make it clearer?
Oct 22 '10 #4

P: n/a
Thank you. I figured out how to do it. The report was based on a query which contained the parameter. Instead of a parameter, I put where the query should find the value to use which is in a form. I used [Forms]![table]![field] and it worked great.
Oct 23 '10 #5

NeoPa
Expert Mod 15k+
P: 31,419
That's certainly another way to redesign the query. Not my preference but Ibelieve it's popular amongst many.
Oct 25 '10 #6

Post your reply

Sign in to post your reply or Sign up for a free account.