Group:  Microsoft Access ยป microsoft.public.access.formscoding
Thread: Run Different Reports with Same Button

Geek News

Run Different Reports with Same Button
Angelsnecropolis 11/19/2008 5:26:04 PM
I have a combo box named "ReportList" and a button named "GenerateReport" on
a form. I'm trying to make the report selected in the combo box run when the
one button is pressed as opposed to making several buttons for each report.

I'm using the code below for a button for each report:

Private Sub GenerateReport_Click()
On Error GoTo Err_GenerateReport_Click

Dim stDocName As String

stDocName = "Takeovers - Kevin"
DoCmd.OpenReport stDocName, acPreview

Exit_GenerateReport_Click:
Exit Sub

Err_GenerateReport_Click:
MsgBox Err.Description
Resume Exit_GenerateReport_Click

End Sub


Thanks!
Re: Run Different Reports with Same Button
"Douglas J. Steele" <NOSPAM_djsteele[ at ]NOSPAM_gmail.com> 11/19/2008 5:38:10 PM
Private Sub GenerateReport_Click()
On Error GoTo Err_GenerateReport_Click

If IsNull(Me!ReportList Then
MsgBox "You must select a report first."
Else
DoCmd.OpenReport Me!ReportList, acPreview
End If

Exit_GenerateReport_Click:
Exit Sub

Err_GenerateReport_Click:
MsgBox Err.Description
Resume Exit_GenerateReport_Click

End Sub


--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Angelsnecropolis" <Angelsnecropolis[ at ]discussions.microsoft.com> wrote in
message news:B67E358E-594A-41B9-A7EA-6766C3572DF9[ at ]microsoft.com...
[Quoted Text]
>I have a combo box named "ReportList" and a button named "GenerateReport"
>on
> a form. I'm trying to make the report selected in the combo box run when
> the
> one button is pressed as opposed to making several buttons for each
> report.
>
> I'm using the code below for a button for each report:
>
> Private Sub GenerateReport_Click()
> On Error GoTo Err_GenerateReport_Click
>
> Dim stDocName As String
>
> stDocName = "Takeovers - Kevin"
> DoCmd.OpenReport stDocName, acPreview
>
> Exit_GenerateReport_Click:
> Exit Sub
>
> Err_GenerateReport_Click:
> MsgBox Err.Description
> Resume Exit_GenerateReport_Click
>
> End Sub
>
>
> Thanks!


Re: Run Different Reports with Same Button
fredg <fgutkind[ at ]example.invalid> 11/19/2008 5:45:33 PM
On Wed, 19 Nov 2008 09:26:04 -0800, Angelsnecropolis wrote:

[Quoted Text]
> I have a combo box named "ReportList" and a button named "GenerateReport" on
> a form. I'm trying to make the report selected in the combo box run when the
> one button is pressed as opposed to making several buttons for each report.
>
> I'm using the code below for a button for each report:
>
Private Sub GenerateReport_Click()
On Error GoTo Err_GenerateReport_Click

If Not IsNull(Me![ReportList]) Then
DoCmd.OpenReport Me![ReportList], acPreview
End If

Exit_GenerateReport_Click:
Exit Sub

Err_GenerateReport_Click:
MsgBox Err.Description
Resume Exit_GenerateReport_Click

End Sub

Why use a command button?
Why not simply code the ReportList AfterUpdate event:

DoCmd.OpenReport Me.[ReportList], acPreview

--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
Re: Run Different Reports with Same Button
"Douglas J. Steele" <NOSPAM_djsteele[ at ]NOSPAM_gmail.com> 11/19/2008 5:47:45 PM
Ooops. Left off a closing parenthesis:

Private Sub GenerateReport_Click()
On Error GoTo Err_GenerateReport_Click

If IsNull(Me!ReportList) Then
MsgBox "You must select a report first."
Else
DoCmd.OpenReport Me!ReportList, acPreview
End If

Exit_GenerateReport_Click:
Exit Sub

Err_GenerateReport_Click:
MsgBox Err.Description
Resume Exit_GenerateReport_Click

End Sub


--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Douglas J. Steele" <NOSPAM_djsteele[ at ]NOSPAM_gmail.com> wrote in message
news:eFSgZ2mSJHA.4084[ at ]TK2MSFTNGP04.phx.gbl...
[Quoted Text]
> Private Sub GenerateReport_Click()
> On Error GoTo Err_GenerateReport_Click
>
> If IsNull(Me!ReportList Then
> MsgBox "You must select a report first."
> Else
> DoCmd.OpenReport Me!ReportList, acPreview
> End If
>
> Exit_GenerateReport_Click:
> Exit Sub
>
> Err_GenerateReport_Click:
> MsgBox Err.Description
> Resume Exit_GenerateReport_Click
>
> End Sub
>
>
> --
> Doug Steele, Microsoft Access MVP
> http://I.Am/DougSteele
> (no e-mails, please!)
>
>
> "Angelsnecropolis" <Angelsnecropolis[ at ]discussions.microsoft.com> wrote in
> message news:B67E358E-594A-41B9-A7EA-6766C3572DF9[ at ]microsoft.com...
>>I have a combo box named "ReportList" and a button named "GenerateReport"
>>on
>> a form. I'm trying to make the report selected in the combo box run when
>> the
>> one button is pressed as opposed to making several buttons for each
>> report.
>>
>> I'm using the code below for a button for each report:
>>
>> Private Sub GenerateReport_Click()
>> On Error GoTo Err_GenerateReport_Click
>>
>> Dim stDocName As String
>>
>> stDocName = "Takeovers - Kevin"
>> DoCmd.OpenReport stDocName, acPreview
>>
>> Exit_GenerateReport_Click:
>> Exit Sub
>>
>> Err_GenerateReport_Click:
>> MsgBox Err.Description
>> Resume Exit_GenerateReport_Click
>>
>> End Sub
>>
>>
>> Thanks!
>
>


Re: Run Different Reports with Same Button
Angelsnecropolis 11/23/2008 12:11:01 AM
Works Beautifully! Thanks! You're awesome!

"Douglas J. Steele" wrote:

[Quoted Text]
> Ooops. Left off a closing parenthesis:
>
> Private Sub GenerateReport_Click()
> On Error GoTo Err_GenerateReport_Click
>
> If IsNull(Me!ReportList) Then
> MsgBox "You must select a report first."
> Else
> DoCmd.OpenReport Me!ReportList, acPreview
> End If
>
> Exit_GenerateReport_Click:
> Exit Sub
>
> Err_GenerateReport_Click:
> MsgBox Err.Description
> Resume Exit_GenerateReport_Click
>
> End Sub
>
>
> --
> Doug Steele, Microsoft Access MVP
> http://I.Am/DougSteele
> (no e-mails, please!)
>
>
> "Douglas J. Steele" <NOSPAM_djsteele[ at ]NOSPAM_gmail.com> wrote in message
> news:eFSgZ2mSJHA.4084[ at ]TK2MSFTNGP04.phx.gbl...
> > Private Sub GenerateReport_Click()
> > On Error GoTo Err_GenerateReport_Click
> >
> > If IsNull(Me!ReportList Then
> > MsgBox "You must select a report first."
> > Else
> > DoCmd.OpenReport Me!ReportList, acPreview
> > End If
> >
> > Exit_GenerateReport_Click:
> > Exit Sub
> >
> > Err_GenerateReport_Click:
> > MsgBox Err.Description
> > Resume Exit_GenerateReport_Click
> >
> > End Sub
> >
> >
> > --
> > Doug Steele, Microsoft Access MVP
> > http://I.Am/DougSteele
> > (no e-mails, please!)
> >
> >
> > "Angelsnecropolis" <Angelsnecropolis[ at ]discussions.microsoft.com> wrote in
> > message news:B67E358E-594A-41B9-A7EA-6766C3572DF9[ at ]microsoft.com...
> >>I have a combo box named "ReportList" and a button named "GenerateReport"
> >>on
> >> a form. I'm trying to make the report selected in the combo box run when
> >> the
> >> one button is pressed as opposed to making several buttons for each
> >> report.
> >>
> >> I'm using the code below for a button for each report:
> >>
> >> Private Sub GenerateReport_Click()
> >> On Error GoTo Err_GenerateReport_Click
> >>
> >> Dim stDocName As String
> >>
> >> stDocName = "Takeovers - Kevin"
> >> DoCmd.OpenReport stDocName, acPreview
> >>
> >> Exit_GenerateReport_Click:
> >> Exit Sub
> >>
> >> Err_GenerateReport_Click:
> >> MsgBox Err.Description
> >> Resume Exit_GenerateReport_Click
> >>
> >> End Sub
> >>
> >>
> >> Thanks!
> >
> >
>
>
>

Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net