PC Review


Reply
Thread Tools Rate Thread

Combo Box Selection to Preview Report

 
 
John1967
Guest
Posts: n/a
 
      10th Apr 2009
I have a combo box that contains 3 items; I want the user to select one item
and for that selection to initiate a macro to open a report in preview mode.
I have created 3 reports and 3 macros. Sounds simple in concept but I just
can't seem to get the right code to do what I need. Would I use If, Then,
Else logic here?

Combo Box:
Main Issue
Contributor
Status

Macros:
OpenReport Main Issue
OpenReport Contributor
OpenReport Status

Thanks for any advice to this Access newbie.
John----
 
Reply With Quote
 
 
 
 
Philip Herlihy
Guest
Posts: n/a
 
      10th Apr 2009
John1967 wrote:
> I have a combo box that contains 3 items; I want the user to select one item
> and for that selection to initiate a macro to open a report in preview mode.
> I have created 3 reports and 3 macros. Sounds simple in concept but I just
> can't seem to get the right code to do what I need. Would I use If, Then,
> Else logic here?
>
> Combo Box:
> Main Issue
> Contributor
> Status
>
> Macros:
> OpenReport Main Issue
> OpenReport Contributor
> OpenReport Status
>
> Thanks for any advice to this Access newbie.
> John----


What I'd do:

Create a table to contain the list of report names, but with a numeric
(integer) ID field as the first field. Make the ID the primary key -
you'll need to enter unique values.

Create my combo box with the wizard turned ON, so that it asks you how
it should be set up. Choose the table of report names as the control
source, and store the numeric identifier but choose to hide it ("key
column") in the combo box display when asked. This'll make sense when
you run it if it doesn't now - Access wizards are brilliant.

In the combo-box properties page, click the selector at the end of the
After Update event - choose "Code Builder". I always use code modules -
allows you to include error code. See:
http://allenbrowne.com/ser-23a.html
(just the 9 numbered lines will do).

In the body of your event handler, use a SELECT ... CASE statement based
on the numeric value of the (updated) combo box to launch the report you
want (or a msgbox alert in the CASE ELSE branch).

Launch the report using:
DoCmd.OpenReport <reportname>, (see Help for other arguments).

Yup, that's essentially a macro, but this way it can be wrapped in error
handling code.

I still shudder at the recollection of the day I decided not to test for
errors in a particularly important function I was writing because
"that'll only generate an error if I've made a programming mistake". O,
the arrogance of youth... Later I'd wrapped this code in another
function, passing in a critical argument and introducing a (common)
programming mistake. Took us weeks to find it. Always use error
handling code.

HTH

Phil, London
 
Reply With Quote
 
 
 
 
Beetle
Guest
Posts: n/a
 
      10th Apr 2009
I agree that this would be better done in code rather than macros.
Here is another option if you only have the three report names to
deal with and you dont think there will be many more in the future.

One question would be do you want the report to open as soon as they
make a selection in the combo box? Or do you want them to make a
selection and then click a command button on the form?

If the former, then the code example below would go in the After Update
event of the combo box. If the latter then it would go in the Click event
of the command button.

The following example code assumes a combo box name of
cboSelectReport with a simple value list of three report names.



Dim strReportName As String

strReportName = Me!cboSelectReport

DoCmd.OpenReport strReportname, acViewPreview



--
_________

Sean Bailey


"John1967" wrote:

> I have a combo box that contains 3 items; I want the user to select one item
> and for that selection to initiate a macro to open a report in preview mode.
> I have created 3 reports and 3 macros. Sounds simple in concept but I just
> can't seem to get the right code to do what I need. Would I use If, Then,
> Else logic here?
>
> Combo Box:
> Main Issue
> Contributor
> Status
>
> Macros:
> OpenReport Main Issue
> OpenReport Contributor
> OpenReport Status
>
> Thanks for any advice to this Access newbie.
> John----

 
Reply With Quote
 
John1967
Guest
Posts: n/a
 
      10th Apr 2009
Thanks Phil and Sean. It's working now.
--
John----


"Beetle" wrote:

> I agree that this would be better done in code rather than macros.
> Here is another option if you only have the three report names to
> deal with and you dont think there will be many more in the future.
>
> One question would be do you want the report to open as soon as they
> make a selection in the combo box? Or do you want them to make a
> selection and then click a command button on the form?
>
> If the former, then the code example below would go in the After Update
> event of the combo box. If the latter then it would go in the Click event
> of the command button.
>
> The following example code assumes a combo box name of
> cboSelectReport with a simple value list of three report names.
>
>
>
> Dim strReportName As String
>
> strReportName = Me!cboSelectReport
>
> DoCmd.OpenReport strReportname, acViewPreview
>
>
>
> --
> _________
>
> Sean Bailey
>
>
> "John1967" wrote:
>
> > I have a combo box that contains 3 items; I want the user to select one item
> > and for that selection to initiate a macro to open a report in preview mode.
> > I have created 3 reports and 3 macros. Sounds simple in concept but I just
> > can't seem to get the right code to do what I need. Would I use If, Then,
> > Else logic here?
> >
> > Combo Box:
> > Main Issue
> > Contributor
> > Status
> >
> > Macros:
> > OpenReport Main Issue
> > OpenReport Contributor
> > OpenReport Status
> >
> > Thanks for any advice to this Access newbie.
> > John----

 
Reply With Quote
 
New Member
Join Date: Apr 2009
Posts: 1
 
      29th Apr 2009
Quote:
Originally Posted by Philip Herlihy
John1967 wrote:
> I have a combo box that contains 3 items; I want the user to select one item
> and for that selection to initiate a macro to open a report in preview mode.
> I have created 3 reports and 3 macros. Sounds simple in concept but I just
> can't seem to get the right code to do what I need. Would I use If, Then,
> Else logic here?
>
> Combo Box:
> Main Issue
> Contributor
> Status
>
> Macros:
> OpenReport Main Issue
> OpenReport Contributor
> OpenReport Status
>
> Thanks for any advice to this Access newbie.
> John----


What I'd do:

Create a table to contain the list of report names, but with a numeric
(integer) ID field as the first field. Make the ID the primary key -
you'll need to enter unique values.

Create my combo box with the wizard turned ON, so that it asks you how
it should be set up. Choose the table of report names as the control
source, and store the numeric identifier but choose to hide it ("key
column") in the combo box display when asked. This'll make sense when
you run it if it doesn't now - Access wizards are brilliant.

In the combo-box properties page, click the selector at the end of the
After Update event - choose "Code Builder". I always use code modules -
allows you to include error code. See:
http://allenbrowne.com/ser-23a.html
(just the 9 numbered lines will do).

In the body of your event handler, use a SELECT ... CASE statement based
on the numeric value of the (updated) combo box to launch the report you
want (or a msgbox alert in the CASE ELSE branch).

Launch the report using:
DoCmd.OpenReport , (see Help for other arguments).

Yup, that's essentially a macro, but this way it can be wrapped in error
handling code.

I still shudder at the recollection of the day I decided not to test for
errors in a particularly important function I was writing because
"that'll only generate an error if I've made a programming mistake". O,
the arrogance of youth... Later I'd wrapped this code in another
function, passing in a critical argument and introducing a (common)
programming mistake. Took us weeks to find it. Always use error
handling code.

HTH

Phil, London
Help! Tried to follow this to do the same thing, but it's not working.

This is the code I have used, but when I select North report from the drop down menu in the form, nothing happens.

Code:
Private Sub Combo138_AfterUpdate()
 
	Select Case ID
	Case 1
		DoCmd.OpenReport ("NORTH Report")
 
	End Select
 
End Sub
To be clear, I have created a Combo Box on a form, which contains a list of 9 reports that are stored in my database. I have created a table with an ID column (autonumbered) and a report name column, with all 9 reports listed.

When I click on the Combo Box in my form I see the 9 reports listed, but clicking on them does nothing.

I would appreciate any help!

Last edited by davidjearly; 29th Apr 2009 at 10:45 AM..
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Clearing combo box selection in multi select combo box =?Utf-8?B?Qm9iIE1jQ29ybWFjaw==?= Microsoft Access Form Coding 2 11th Feb 2005 04:09 AM
combo box values dependent on user's selection of another combo box jenn Microsoft Access 8 3rd Dec 2004 10:25 PM
using selection from combo box as input to a 2d combo box tonyaims Microsoft Access Forms 13 10th Sep 2004 05:56 PM
using selection in combo box to filter another combo box display =?Utf-8?B?TVJS?= Microsoft Access Form Coding 1 9th Feb 2004 12:57 AM
filtering combo box entries based on the selection of another combo box JulieD Microsoft Access Forms 1 4th Nov 2003 10:46 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:14 PM.