Passing Parameters from Button to Form

  • Thread starter Thread starter Tommy T
  • Start date Start date
T

Tommy T

Hello everyone,

I currently have 2 Unbound Query-by-Forms that are opened from 2 buttons,
respectively, on a master form. The Query-by-Form prompts the user for a
StartDate and an EndDate with the addition of a button to open its
respective report and a close button. The Query-by-Forms are almost
identical except for the Caption and the report that each opens.

I would like to use only one Query-by-Form and pass parameters from the
master form's button through the Query-by-Form to the Report. If I can use
naming conventions based on the Tag or a portion of the name of the button
all the way to report I could do that right? But How?

MasterForm:
cmdBtnOpenAuthorizationReportVIAfrmEnterDates1ForAuthorizationReport --->
frmEnterDates1ForAuthorizationReport: Caption = "Authorization Report" --->
stDocName = "RptAuthorizationReport"

The underlying Query shouldn't be affected right? Just as long as it gets
its date parameters from "A" form and the report is based on its respective
data.

I conceptually know what I want to do the question is feasibility and how?

Thanks to anyone with some help on this subject

Tommy "T"
 
Tommy,

I do something like what your trying to do. I use
radiobuttons in an Optiongroup. Each radiobutton is
assigned a value(by the option group). In the OnGotFocus
event I set label captions and make some fields visible
and others not visible. I have one button, call it "Print
Report". When I press the button, I have an If statement
structure that runs something like this:

If (me!optiongroupName=1)then
....
elseif (me!optiongroupName=1)then
....

etc.

End If

When you call the report there should be no problem with
the underlying query as long as you are passing it all the
information it needs.

As I recall to change the label caption, you use:
labelObjectName.Caption="your text"

Hope that helps!

Kevin
 
I am sorry Kevin I guess I was looking for something more specific but
thanks for trying.

Tom
 
You could simply pass the report name to the Query by Form. Check out the
open args.

There are many soltions, but best soltion is to simply remove all of the
paramters from the query.

Then, you use the "where" clause of the open report. That way, you can open
any reprot,a nd pass conditions to that report, but NOT EVEN CARE about the
query, or data souce of hte reprot. In other words, don't use querys with
paramters, but use the "where" clause when you open a report. This give max
flexlbity. In fact, in you case, you could pass 2 parmaters to your small
query form. Those 2 paramters would be:

ReportName
TheDateField

Since the date range fields, and the reprot name is NOT going to be hard
coded, then we need/want to pass those values to our cute little query form.

The code to call this form would look like:

docmd.OpenForm "dlkjf",,,,,,"Form,InvoiceDateField"

Carefully note how 2 things are in ONE string of the openargs.

Now, in your on-load event of the cute query/prompt form, you get:

strReportName = split(me.OpenArgs",",")(0)
strDateField = split(me.OpenArgs",",")(1)

The above strReportName and strStartField etc is defined at the forms MODULE
level.

Now, your code behind the buttion to launch the reprot can look like:

dim strWhere as string

strWhere = "between " & cDateStart & " and " & cDateEnd

strWhere = buildCriteria(strDateField,dbDate,strWhere)

docmd.OpenReprot strReportName,acViewPreview,,strWhere


That should do it. If you take look at the following screen shots, I do the
above all the time:

http://www.attcanada.net/~kallal.msn/ridesrpt/ridesrpt.html
 
You can create the qry first - use the report wizard to create the report
form the qry. Then create a button to open the report and since the qry
hasnt been run yet it will automatically run the qry and ask you for your
dates and then automatically generate the report
 
Back
Top