Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access thread: Report based on a query with parameters


Message #1 by "Olivier Hamel" <hamel_olivier@h...> on Tue, 17 Dec 2002 20:14:07
I have a ComboBox in my form, when i pressed the button under my combobox, 
i want my report to print. This report is based on a query.
Is paramter should be the value of my combo (Combo1.text), but what is 
happening is that everytime i pressed print(button) the little box 
paramter opens. Is there a way using VBA of giving the parameter without 
be prompt ??
Message #2 by "Gregory Serrano" <SerranoG@m...> on Tue, 17 Dec 2002 22:15:02
Olivier,

<< I have a ComboBox in my form, when i pressed the button under my 
combobox, i want my report to print. This report is based on a query.  Is 
paramter should be the value of my combo (Combo1.text), but what is 
happening is that everytime i pressed print(button) the little box 
paramter opens. Is there a way using VBA of giving the parameter without 
be prompt ?? >>

Try this approach on your button's "On Click" event.

   Dim strDocName As String, strLinkCriteria As String

   strDocName = "rptMyReportName"
   strLinkCriteria =  "[strMyTextField] = '" & Me.cboMyComboBoxText & "'"
   DoCmd.OpenReport strDocName, acViewPreview, , strLinkCriteria


Greg
Message #3 by "Olivier Hamel" <hamel_olivier@h...> on Wed, 18 Dec 2002 19:10:05
> Olivier,

> << I have a ComboBox in my form, when i pressed the button under my 
c> ombobox, i want my report to print. This report is based on a query.  
Is 
p> aramter should be the value of my combo (Combo1.text), but what is 
h> appening is that everytime i pressed print(button) the little box 
p> aramter opens. Is there a way using VBA of giving the parameter without 
b> e prompt ?? >>

> Try this approach on your button's "On Click" event.

>    Dim strDocName As String, strLinkCriteria As String

>    strDocName = "rptMyReportName"
 >   strLinkCriteria =  "[strMyTextField] = '" & Me.cboMyComboBoxText & "'"
 >   DoCmd.OpenReport strDocName, acViewPreview, , strLinkCriteria

> 
G> reg

No it's not working, the prompt box asking me for the parameter value is 
still popping :-( you have other idea ??
Message #4 by "John Ruff" <papparuff@a...> on Wed, 18 Dec 2002 15:49:52 -0800
Oliver,

Using Gregory's suggested method works beautifully but will not get rid 
of
your parameter message.  What you need to do is change your query from a
parameter to a select.  In other words, do away with the parameters in 
the
query.

Also, one thing to remember when using a criteria in opening the report.
You can have basically three types of variables to filter the report on;
String, Date, and Number.  Thus the criteria will be formatted a bit
different for each one.  Here are examples of each:

Text field:
strLinkCriteria =3D  "[LastName] =3D '" & cboMyComboBox & "'"
Numeric field:
strLinkCriteria =3D  "[ClientID] =3D " & cboMyComboBox
Date field:
strLinkCriteria =3D  "[OrderDate] =3D #" & cboMyComboBox & "#"

Also, you can build a criteria that is based on a range.  The most 
common is
a From Date and a Thru date.
So, you could have two comboboxes on your form asking for a From Date
(cboFromDate) and a Thru Date (cboThruDate).  Your criteria could look 
like
this:

strLinkCriter=3D"[OrderDate] >=3D #" & cboFromDate & "# AND [OrderDate] 
<=3D#" &
cboFromDate & "#"


John V. Ruff - The Eternal Optimist :-)
Always Looking For Contract Opportunities

www.noclassroom.com
Live software training
Right over the Internet

Home:  xxx.xxx.xxxx
Cell: 253.307/2947
9306 Farwest Dr SW
Lakewood, WA 98498

"Commit to the Lord whatever you do,
	and your plans will succeed." Proverbs 16:3



-----Original Message-----
From: Olivier Hamel [mailto:hamel_olivier@h...]
Sent: Wednesday, December 18, 2002 7:10 PM
To: Access
Subject: [access] Re: Report based on a query with parameters


> Olivier,

> << I have a ComboBox in my form, when i pressed the button under my
c> ombobox, i want my report to print. This report is based on a query.
Is
p> aramter should be the value of my combo (Combo1.text), but what is
h> appening is that everytime i pressed print(button) the little box
p> aramter opens. Is there a way using VBA of giving the parameter
p> without
b> e prompt ?? >>

> Try this approach on your button's "On Click" event.

>    Dim strDocName As String, strLinkCriteria As String

>    strDocName =3D "rptMyReportName"
 >   strLinkCriteria =3D  "[strMyTextField] =3D '" & 
Me.cboMyComboBoxText & "'"
 >   DoCmd.OpenReport strDocName, acViewPreview, , strLinkCriteria

>
G> reg

No it's not working, the prompt box asking me for the parameter value is 

still popping :-( you have other idea ??


Message #5 by "John Ruff" <papparuff@a...> on Wed, 18 Dec 2002 16:02:47 -0800
I'm reposting this as the original looks totally confusing in the format 
it
was sent in.  Hopefully, this will be formatted properly.

Oliver,

Using Gregory's suggested method works beautifully but will not get rid 
of
your parameter message.  What you need to do is change your query from a
parameter to a select.  In other words, do away with the parameters in 
the
query.

Also, one thing to remember when using a criteria in opening the report.
You can have basically three types of variables to filter the report on;
String, Date, and Number.  Thus the criteria will be formatted a bit
different for each one.  Here are examples of each:

Text field:
strLinkCriteria =3D  "[LastName] =3D '" & cboMyComboBox & "'"

Numeric field:
strLinkCriteria =3D  "[ClientID] =3D " & cboMyComboBox

Date field:
strLinkCriteria =3D  "[OrderDate] =3D #" & cboMyComboBox & "#"

Also, you can build a criteria that is based on a range.  The most 
common is
a From Date and a Thru date. So, you could have two comboboxes on your 
form
asking for a From Date (cboFromDate) and a Thru Date (cboThruDate).  
Your
criteria could look like this:

strLinkCriter=3D"[OrderDate] >=3D #" & cboFromDate & "# AND [OrderDate] 
<=3D#" &
cboFromDate & "#"


John V. Ruff - The Eternal Optimist :-)
Always Looking For Contract Opportunities

www.noclassroom.com
Live software training
Right over the Internet

Home:  xxx.xxx.xxxx
Cell: 253.307/2947
9306 Farwest Dr SW
Lakewood, WA 98498

"Commit to the Lord whatever you do,
	and your plans will succeed." Proverbs 16:3



-----Original Message-----
From: Olivier Hamel [mailto:hamel_olivier@h...]
Sent: Wednesday, December 18, 2002 7:10 PM
To: Access
Subject: [access] Re: Report based on a query with parameters


> Olivier,

> << I have a ComboBox in my form, when i pressed the button under my
c> ombobox, i want my report to print. This report is based on a query.
Is
p> aramter should be the value of my combo (Combo1.text), but what is
h> appening is that everytime i pressed print(button) the little box
p> aramter opens. Is there a way using VBA of giving the parameter
p> without
b> e prompt ?? >>

> Try this approach on your button's "On Click" event.

>    Dim strDocName As String, strLinkCriteria As String

>    strDocName =3D "rptMyReportName"
 >   strLinkCriteria =3D  "[strMyTextField] =3D '" & 
Me.cboMyComboBoxText & "'"
 >   DoCmd.OpenReport strDocName, acViewPreview, , strLinkCriteria

>
G> reg

No it's not working, the prompt box asking me for the parameter value is 

still popping :-( you have other idea ??


Message #6 by "Bob Bedell" <bobbedell15@m...> on Thu, 19 Dec 2002 06:02:58 +0000
>I have a ComboBox in my form, when i pressed the button under my
>combobox, i want my report to print. This report is based on a query.
>Is paramter should be the value of my combo (Combo1.text)

Also be aware that:

strLinkCriteria =  "[ClientID] = " & cboMyComboBox

is assigning the value of the Value property of your combo box to
strLinkCriteria, and not the value of the Text property of your combo
box, as you indicate you want in your post (Combo1.text).

The Value property is the default property of combo boxes and is
assumed in the line of code above, since the Text property isn't
explicitly indicated. The Text property contains the text data
currently displayed in your combo; the Value property contains the
value saved in your combo's control source (underlying field) and
referenced by the bound column. If your displayed column and your bound
column are the same, the combo box's Text and Value property values
will be the same. My bound column is usually hidden, in which case the
combo box's Text and Value property values are usually different.

Unfortunately, the Text property isn't available in code if the combo
box doesn't have the focus, and yours won't because you are invoking
your report by pressing a command button.  So:

strLinkCriteria =  "[ClientID] = " & cboMyComboBox.Text

won't work (or Combo1.text as you indicate above). Try

strLinkCriteria =  "[ClientID] = " & cboMyComboBox

or one of the other versions Greg and John mentioned, but be sure that
[ClientID], or whatever your criteria field is named, is the control
source field of your combo box, and that you have the appropriate
column bound to this field. The bound column may or may not be the
combo box's displayed column (the value of which is stored in
Comb1.text)

The following sub might help you sort out how these two properties
are behaving behind the scenes:

Private Sub Form_Current()
    Me.cboMyComboBox.SetFocus
    Debug.Print Me.cboMyComboBox.Text
    Debug.Print Me.cboMyComboBox.Value
End Sub

Of course, you could be getting those parameter boxes because you
have the name of a control or a parameter expression mispelled.

Best,

Bob


>From: "John Ruff" <papparuff@a...>
>Reply-To: "Access" <access@p...>
>To: "Access" <access@p...>
>Subject: [access] Re: Report based on a query with parameters
>Date: Wed, 18 Dec 2002 16:02:47 -0800
>
>I'm reposting this as the original looks totally confusing in the format it
>was sent in.  Hopefully, this will be formatted properly.
>
>Oliver,
>
>Using Gregory's suggested method works beautifully but will not get rid of
>your parameter message.  What you need to do is change your query from a
>parameter to a select.  In other words, do away with the parameters in the
>query.
>
>Also, one thing to remember when using a criteria in opening the report.
>You can have basically three types of variables to filter the report on;
>String, Date, and Number.  Thus the criteria will be formatted a bit
>different for each one.  Here are examples of each:
>
>Text field:
>strLinkCriteria =  "[LastName] = '" & cboMyComboBox & "'"
>
>Numeric field:
>strLinkCriteria =  "[ClientID] = " & cboMyComboBox
>
>Date field:
>strLinkCriteria =  "[OrderDate] = #" & cboMyComboBox & "#"
>
>Also, you can build a criteria that is based on a range.  The most common 
>is
>a From Date and a Thru date. So, you could have two comboboxes on your form
>asking for a From Date (cboFromDate) and a Thru Date (cboThruDate).  Your
>criteria could look like this:
>
>strLinkCriter="[OrderDate] >= #" & cboFromDate & "# AND [OrderDate] <=#" &
>cboFromDate & "#"
>
>
>John V. Ruff - The Eternal Optimist :-)
>Always Looking For Contract Opportunities
>
>www.noclassroom.com
>Live software training
>Right over the Internet
>
>Home:  xxx.xxx.xxxx
>Cell: 253.307/2947
>9306 Farwest Dr SW
>Lakewood, WA 98498
>
>"Commit to the Lord whatever you do,
>	and your plans will succeed." Proverbs 16:3
>
>
>
>-----Original Message-----
>From: Olivier Hamel [mailto:hamel_olivier@h...]
>Sent: Wednesday, December 18, 2002 7:10 PM
>To: Access
>Subject: [access] Re: Report based on a query with parameters
>
>
> > Olivier,
>
> > << I have a ComboBox in my form, when i pressed the button under my
>c> ombobox, i want my report to print. This report is based on a query.
>Is
>p> aramter should be the value of my combo (Combo1.text), but what is
>h> appening is that everytime i pressed print(button) the little box
>p> aramter opens. Is there a way using VBA of giving the parameter
>p> without
>b> e prompt ?? >>
>
> > Try this approach on your button's "On Click" event.
>
> >    Dim strDocName As String, strLinkCriteria As String
>
> >    strDocName = "rptMyReportName"
>  >   strLinkCriteria =  "[strMyTextField] = '" & Me.cboMyComboBoxText & 
>"'"
>  >   DoCmd.OpenReport strDocName, acViewPreview, , strLinkCriteria
>
> >
>G> reg
>
>No it's not working, the prompt box asking me for the parameter value is
>still popping :-( you have other idea ??
>
>
>


_________________________________________________________________
Protect your PC - get McAfee.com VirusScan Online 
http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963


  Return to Index