WUGNET, the Windows User Group Network
Your Complete Resource Center for "The Best" in Shareware, Computing Tips and Support, Windows Industry News... and much more!
Home Forums Shareware Windows Tips Hot Offers FREE Newsletters Arcade Contact Us About Partners
Search WUGNET: RSS Feeds RSS Feeds Advertise with WUGNET    |    Shareware eBooks
HomeHome FAQFAQ      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

2 reports based on one query

 
   Home -> Office other -> Reports RSS
Next:  error 11003  
Author Message
randria

External


Since: Sep 01, 2008
Posts: 7



(Msg. 1) Posted: Wed Sep 03, 2008 6:24 am
Post subject: 2 reports based on one query
Archived from groups: microsoft>public>access>reports (more info?)

Hello,

I have a form that supplies parameters to a query. I have 2 different
reports ( OSrpt and ONrpt ) depending on this query. I want to preview OSrpt
if the categorieID of the supplier selected by the user is equal to 1 and if
not to preview ONrpt instead.
this is the code I used but it selects only "ONrpt".

Private Sub Command6_Click()
On Error GoTo Err_Command6_Click
Dim stDocName As String
Dim CategorieID As long
if CategorieID=1 Then
stDocName = "OSrpt"
DoCmd.OpenReport stDocName, acPreview
else
stDocName= "ONrpt"
DoCmd.OpenReport stDocName, acPreview
End if

Exit_Command6_Click:
Exit Sub

Err_Command6_Click:
MsgBox Err.Description
Resume Exit_Command6_Click

End Sub

the problem is that even if the 1st condition is true, it displays the
records on the report "ONrpt".
Many thanks.
randria
Back to top
Login to vote
Jeff Boyce

External


Since: Nov 04, 2004
Posts: 3937



(Msg. 2) Posted: Wed Sep 03, 2008 8:08 am
Post subject: Re: 2 reports based on one query [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

If this were mine, I'd add a breakpoint into the code and run it, stepping
through each line to figure out if/where it "breaks".

Regards

Jeff Boyce
Microsoft Office/Access MVP

"randria" <randria DeleteThis @discussions.microsoft.com> wrote in message
news:EB1E9FC7-64BB-4DB5-9419-959D44FDC09E@microsoft.com...
> Hello,
>
> I have a form that supplies parameters to a query. I have 2 different
> reports ( OSrpt and ONrpt ) depending on this query. I want to preview
> OSrpt
> if the categorieID of the supplier selected by the user is equal to 1 and
> if
> not to preview ONrpt instead.
> this is the code I used but it selects only "ONrpt".
>
> Private Sub Command6_Click()
> On Error GoTo Err_Command6_Click
> Dim stDocName As String
> Dim CategorieID As long
> if CategorieID=1 Then
> stDocName = "OSrpt"
> DoCmd.OpenReport stDocName, acPreview
> else
> stDocName= "ONrpt"
> DoCmd.OpenReport stDocName, acPreview
> End if
>
> Exit_Command6_Click:
> Exit Sub
>
> Err_Command6_Click:
> MsgBox Err.Description
> Resume Exit_Command6_Click
>
> End Sub
>
> the problem is that even if the 1st condition is true, it displays the
> records on the report "ONrpt".
> Many thanks.
> randria
>
Back to top
Login to vote
fredg

External


Since: Jan 30, 2004
Posts: 4644



(Msg. 3) Posted: Wed Sep 03, 2008 8:14 am
Post subject: Re: 2 reports based on one query [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Wed, 3 Sep 2008 06:24:01 -0700, randria wrote:

> Hello,
>
> I have a form that supplies parameters to a query. I have 2 different
> reports ( OSrpt and ONrpt ) depending on this query. I want to preview OSrpt
> if the categorieID of the supplier selected by the user is equal to 1 and if
> not to preview ONrpt instead.
> this is the code I used but it selects only "ONrpt".
>
> Private Sub Command6_Click()
> On Error GoTo Err_Command6_Click
> Dim stDocName As String
> Dim CategorieID As long
> if CategorieID=1 Then
> stDocName = "OSrpt"
> DoCmd.OpenReport stDocName, acPreview
> else
> stDocName= "ONrpt"
> DoCmd.OpenReport stDocName, acPreview
> End if
>
> Exit_Command6_Click:
> Exit Sub
>
> Err_Command6_Click:
> MsgBox Err.Description
> Resume Exit_Command6_Click
>
> End Sub
>
> the problem is that even if the 1st condition is true, it displays the
> records on the report "ONrpt".
> Many thanks.
> randria

Regarding ...
Dim CategorieID As long
if CategorieID=1 Then
When your code runs, CategorieID is ALWAYS 0.
No where in the above to you give it a value.

If the only difference between the 2 reports is the criteria, then you
should have just one report, and filter the data using the Where
clause argument of the OpenReport method. See VBA help on the
OpenReport method and also
Where clause + Restrict data to a subset of records.

If there is more than just the criteria difference between the 2
reports, then you must give CategoryID a value, i.e.
Dim CategoryID as Long
CategoryID = [SomeControlValue]
If CategoryID = 1 Then
.... etc...

Though if you are doing that, then it's just simpler to use:

Dim stDocName as String
If [SomeControlValue] = 1 then
stDocName = "OSrpt"
Else
stDocName = "ONrpt"
End If
DoCmd.OpenReport stDocName, acViewPreview


--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
Back to top
Login to vote
Marshall Barton

External


Since: Dec 07, 2003
Posts: 6117



(Msg. 4) Posted: Wed Sep 03, 2008 10:19 am
Post subject: Re: 2 reports based on one query [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

randria wrote:
>I have a form that supplies parameters to a query. I have 2 different
>reports ( OSrpt and ONrpt ) depending on this query. I want to preview OSrpt
>if the categorieID of the supplier selected by the user is equal to 1 and if
>not to preview ONrpt instead.
>this is the code I used but it selects only "ONrpt".
>
>Private Sub Command6_Click()
>On Error GoTo Err_Command6_Click
>Dim stDocName As String
>Dim CategorieID As long
> if CategorieID=1 Then
> stDocName = "OSrpt"
> DoCmd.OpenReport stDocName, acPreview
>else
> stDocName= "ONrpt"
> DoCmd.OpenReport stDocName, acPreview
>End if
>
>Exit_Command6_Click:
>Exit Sub
>
>Err_Command6_Click:
>MsgBox Err.Description
>Resume Exit_Command6_Click
>
>End Sub


If CategorieID is a control on the form, then remove the
line:
Dim CategorieID As Long

--
Marsh
MVP [MS Access]
Back to top
Login to vote
randria

External


Since: Sep 01, 2008
Posts: 7



(Msg. 5) Posted: Wed Sep 03, 2008 6:05 pm
Post subject: Re: 2 reports based on one query [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Hi Jeff, Fred and Marshall

Many thanks for your repiies they all gave me some useful options, I have to
have 2 reports and Fred's code solved the problem. Below is the code:

Private Sub Command6_Click()
On Error GoTo Err_Command6_Click
Dim stDocName As String
Dim CategorieID As long
CategorieID=[cbo0] ' this is what was missing the combo on the form.
if CategorieID=1 Then
stDocName = "OSrpt"
DoCmd.OpenReport stDocName, acPreview
else
stDocName= "ONrpt"
DoCmd.OpenReport stDocName, acPreview
End if

Exit_Command6_Click:
Exit Sub

Err_Command6_Click:
MsgBox Err.Description
Resume Exit_Command6_Click

End Sub
Many thanks.

"fredg" wrote:

> On Wed, 3 Sep 2008 06:24:01 -0700, randria wrote:
>
> > Hello,
> >
> > I have a form that supplies parameters to a query. I have 2 different
> > reports ( OSrpt and ONrpt ) depending on this query. I want to preview OSrpt
> > if the categorieID of the supplier selected by the user is equal to 1 and if
> > not to preview ONrpt instead.
> > this is the code I used but it selects only "ONrpt".
> >
> > Private Sub Command6_Click()
> > On Error GoTo Err_Command6_Click
> > Dim stDocName As String
> > Dim CategorieID As long
> > if CategorieID=1 Then
> > stDocName = "OSrpt"
> > DoCmd.OpenReport stDocName, acPreview
> > else
> > stDocName= "ONrpt"
> > DoCmd.OpenReport stDocName, acPreview
> > End if
> >
> > Exit_Command6_Click:
> > Exit Sub
> >
> > Err_Command6_Click:
> > MsgBox Err.Description
> > Resume Exit_Command6_Click
> >
> > End Sub
> >
> > the problem is that even if the 1st condition is true, it displays the
> > records on the report "ONrpt".
> > Many thanks.
> > randria
>
> Regarding ...
> Dim CategorieID As long
> if CategorieID=1 Then
> When your code runs, CategorieID is ALWAYS 0.
> No where in the above to you give it a value.
>
> If the only difference between the 2 reports is the criteria, then you
> should have just one report, and filter the data using the Where
> clause argument of the OpenReport method. See VBA help on the
> OpenReport method and also
> Where clause + Restrict data to a subset of records.
>
> If there is more than just the criteria difference between the 2
> reports, then you must give CategoryID a value, i.e.
> Dim CategoryID as Long
> CategoryID = [SomeControlValue]
> If CategoryID = 1 Then
> .... etc...
>
> Though if you are doing that, then it's just simpler to use:
>
> Dim stDocName as String
> If [SomeControlValue] = 1 then
> stDocName = "OSrpt"
> Else
> stDocName = "ONrpt"
> End If
> DoCmd.OpenReport stDocName, acViewPreview
>
>
> --
> Fred
> Please respond only to this newsgroup.
> I do not reply to personal e-mail
>
Back to top
Login to vote
Display posts from previous:   
       Home -> Office other -> Reports All times are: Eastern Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Categories:
 Windows XP
 Windows Vista
 Windows Other
 Office
  Office Other
 Security
 WinRAR
  • Home |
  • Shareware |
  • Windows Tips |
  • Hot Offers |
  • FREE Newsletters |
  • Arcade |
  • Forums |
  • eBooks |
  • About WUGNET |
  • Partners |
  • Contact

  • WUGNET Privacy Policy |
  • Link to WUGNET