Go Back   Access World Forums > Microsoft Access Discussion > Modules & VBA

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 06-12-2019, 11:35 PM   #1
penchalas
Newly Registered User
 
Join Date: May 2019
Location: india
Posts: 26
Thanks: 1
Thanked 0 Times in 0 Posts
penchalas is on a distinguished road
VBA to open report based on listbox dropdown and button click

Hi All,
I have a form with a list box, button and reports


my requirement is:
1. Select the value form list box drop down
2. Click on button
3. Corresponding report should open based on list drop down selection


Ex: When i select 'customers' in list and click on button, it should open customer report


Please let me know on how to achieve this

penchalas is offline   Reply With Quote
Old 06-12-2019, 11:49 PM   #2
Cronk
Newly Registered User
 
Join Date: Jul 2013
Posts: 2,137
Thanks: 3
Thanked 466 Times in 459 Posts
Cronk will become famous soon enough Cronk will become famous soon enough
Re: VBA to open report based on listbox dropdown and button click

You can achieve this by adding the following code (modified to suit your own circumstances) the the on-click event of the form's button

Code:
select case me.YourListBox & ""
   case "Customers"
      docmd.OpenReport "YourCustomerReport"
   case "OtherReport
      docmd.Openreport "YourOtherReport"
   case ...
      ....
end select
Cronk is offline   Reply With Quote
Old 06-13-2019, 12:25 AM   #3
Minty
AWF VIP
 
Minty's Avatar
 
Join Date: Jul 2013
Location: UK - Wiltshire
Posts: 6,419
Thanks: 162
Thanked 1,734 Times in 1,704 Posts
Minty is a jewel in the rough Minty is a jewel in the rough Minty is a jewel in the rough
Re: VBA to open report based on listbox dropdown and button click

You could populate your listbox with all reports in your database automatically ;

Make the listbox rowsource this;

Code:
SELECT MsysObjects.Name
FROM MsysObjects
WHERE (((MsysObjects.Type)=-32764))
ORDER BY MsysObjects.Name;
Then in your OnClick or Double click event

DoCmd.OpenReport Me.YourListboxName

__________________
If we have helped please add to our reputation - click the scales symbol on the left, tick 'I approve' and leave a comment.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Minty is offline   Reply With Quote
Old 06-13-2019, 12:30 AM   #4
penchalas
Newly Registered User
 
Join Date: May 2019
Location: india
Posts: 26
Thanks: 1
Thanked 0 Times in 0 Posts
penchalas is on a distinguished road
Re: VBA to open report based on listbox dropdown and button click

Quote:
Originally Posted by Cronk View Post
You can achieve this by adding the following code (modified to suit your own circumstances) the the on-click event of the form's button

Code:
select case me.YourListBox & ""
   case "Customers"
      docmd.OpenReport "YourCustomerReport"
   case "OtherReport
      docmd.Openreport "YourOtherReport"
   case ...
      ....
end select

Thanks Much! It worked
penchalas is offline   Reply With Quote
Old 06-13-2019, 06:23 PM   #5
HiTechCoach
Newly Registered User
 
HiTechCoach's Avatar
 
Join Date: Mar 2006
Location: Oklahoma City, OK
Posts: 4,254
Thanks: 8
Thanked 156 Times in 144 Posts
HiTechCoach is a jewel in the rough HiTechCoach is a jewel in the rough HiTechCoach is a jewel in the rough HiTechCoach is a jewel in the rough
Re: VBA to open report based on listbox dropdown and button click

You may also find these examples helpful

Report Dialog Examples
__________________
Boyd Trimmell
Specializing in Accounting, CRM, and Business solutions
Microsoft Access MVP 2010-2015 , aka
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
HiTechCoach is offline   Reply With Quote
Old 06-14-2019, 06:07 AM   #6
penchalas
Newly Registered User
 
Join Date: May 2019
Location: india
Posts: 26
Thanks: 1
Thanked 0 Times in 0 Posts
penchalas is on a distinguished road
Re: VBA to open report based on listbox dropdown and button click

Quote:
Originally Posted by penchalas View Post
Thanks Much! It worked
Can we do the same thing with combo box?
penchalas is offline   Reply With Quote
Old 06-14-2019, 07:02 AM   #7
Minty
AWF VIP
 
Minty's Avatar
 
Join Date: Jul 2013
Location: UK - Wiltshire
Posts: 6,419
Thanks: 162
Thanked 1,734 Times in 1,704 Posts
Minty is a jewel in the rough Minty is a jewel in the rough Minty is a jewel in the rough
Re: VBA to open report based on listbox dropdown and button click

Yes but its not as easy for end users to see / use.

__________________
If we have helped please add to our reputation - click the scales symbol on the left, tick 'I approve' and leave a comment.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Minty is offline   Reply With Quote
Old 06-14-2019, 07:23 AM   #8
smig
Newly Registered User
 
Join Date: Nov 2009
Location: Israel
Posts: 1,960
Thanks: 60
Thanked 131 Times in 122 Posts
smig is on a distinguished road
Re: VBA to open report based on listbox dropdown and button click

look here
https://www.access-programmers.co.uk...84#post1627184

enjoy

smig is offline   Reply With Quote
Reply

Tags
list box , reports , vba

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Button that will open a dropdown henryihunter1954 Forms 4 04-27-2017 04:01 PM
click button to open a dropdown to open a record the filters by dropdown 491 Forms 1 07-28-2014 10:24 AM
Button Click Event to choose between forms to open based on TextBox input u4jaanus Forms 10 06-12-2013 06:00 AM
open report based on combo selection/command button fibayne Reports 3 10-17-2008 05:10 AM
Double click on a listbox to open record spnz Modules & VBA 2 11-29-2005 10:26 AM




All times are GMT -8. The time now is 12:41 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World