setting recordsource

disgruntled

Registered User.
Local time
Today, 15:53
Joined
Jul 3, 2001
Messages
38
Hi...me again
smile.gif

i have one report that is passed along a one of 4 almost identical queries. Therefore, as per wahtever conditions i need to set the recodsource to whichever query applies. I have written the below using 2 different tech's for setting it but it does not like. An error comes up saying "the report 'rptChar is misspelled or does not exist' but it is spelled corrrectlt and does exist. I am thinking it syntax error but any advice would be mucho helpful.
 
woops......forgot the code:

If cbox_Status = "(ALL)" And cbox_Trait = "(ALL)" Then
Reports("rptChar").RecordSource = "qryReport_Chars_none"
DoCmd.OpenReport "rptChar", A_PREVIEW
End If
If cbox_Status <> "(ALL)" And cbox_Trait = "(ALL)" Then
[Reports]![rptChar].RecordSource = "qryReport_Chars_statusonly"
DoCmd.OpenReport "rptChar", A_PREVIEW
End If
If cbox_Status = "(ALL)" And cbox_Trait <> "(ALL)" Then
[Reports]![rptChar].RecordSource = "qryReport_Chars_traitonly"
DoCmd.OpenReport "rptChar", A_PREVIEW
End If
If cbox_Status <> "(ALL)" And cbox_Trait <> "(ALL)" Then
[Reports]![rptChar].RecordSource = "qryReport_Chars"
DoCmd.OpenReport "rptChar", A_PREVIEW
End If
 
If anyone is interested i got a great response in a different group. It will be great if this topic is ever searched again:

"Dirk Goldgar" <dg@NOdataSPAMgnostics.com> wrote in message news:<#HeQRbtJBHA.1128@tkmsftngp02>...
> The Reports collection only holds open reports, so if your report is not yet
> open it won't be in there. What you need to set up is a way for the report
> itself to determine, in its Open event, which query to use as its
> recordsource. Unfortunately, the OpenReport method doesn't let you pass an
> argument to the report (the way OpenForm does for forms), but I can think of
> two simple ways to do this.
>
> (1) If the report is always opened from this form, then the report can look
> at the form to see what the states of the combo boxes are. You'd have code
> like this in the report's Open event:
>
> '---- Warning: air code ----
> Private Sub Report_Open(Cancel As Integer)
>
> Dim frm As Form
>
> On Error Resume Next
> Set frm = Forms!ReportParameters
> If Err.Number = 0 Then
> With frm
> If !cbox_Status = "(ALL)" And !cbox_Trait = "(ALL)" Then
> Me.RecordSource = "qryReport_Chars_none"
> ElseIf !cbox_Status <> "(ALL)" And !cbox_Trait = "(ALL)"
> Then
> Me.RecordSource = "qryReport_Chars_statusonly"
> ElseIf cbox_Status = "(ALL)" And cbox_Trait <> "(ALL)" Then
> Me.RecordSource = "qryReport_Chars_traitonly"
> Else
> Me.RecordSource = "qryReport_Chars"
> End If
> End With
> Set frm = Nothing
> End If
>
> End Sub
> '---- end of code ----
>
> (2) You could alternatively define a global variable -- a Public variable in
> a standard module -- that you will use to communicate with the report.
> Before opening the report, you set this variable to either the name of the
> desired recordsource query, or to a value that the report can use in its
> open event to decide what the recordsource should be. So, for example, you
> could have code like this:
>
> '---- in a standard module somewhere ----
> Public gstrReport_rptChar_Recordsource
>
> '---- in the form's module ----
> If Me!cbox_Status = "(ALL)" And Me!cbox_Trait = "(ALL)" Then
> gstrReport_rptChar_Recordsource = "qryReport_Chars_none"
> ElseIf !cbox_Status <> "(ALL)" And !cbox_Trait = "(ALL)" Then
> gstrReport_rptChar_Recordsource = "qryReport_Chars_statusonly"
> ElseIf cbox_Status = "(ALL)" And cbox_Trait <> "(ALL)" Then
> gstrReport_rptChar_Recordsource = "qryReport_Chars_traitonly"
> Else
> gstrReport_rptChar_Recordsource = "qryReport_Chars"
> End If
> DoCmd.OpenReport "rptChar", A_PREVIEW
>
> '---- in the report's Open event ----
> Private Sub Report_Open(Cancel As Integer)
>
> If Len(gstrReport_rptChar_Recordsource) > 0 Then
> Me.RecordSource = gstrReport_rptChar_Recordsource
> End If
>
> gstrReport_rptChar_Recordsource = ""
>
> End Sub
>
> '---- end of code ----
>
> I hope this gives you some ideas.
>
> --
> Dirk Goldgar
> www.datagnostics.com
 

Users who are viewing this thread

Back
Top Bottom