VBA to open report based on listbox dropdown and button click

penchalas

Registered User.
Local time
Today, 22:27
Joined
May 14, 2019
Messages
26
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
 
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
 
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
 
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 :):)
 
Yes but its not as easy for end users to see / use.
 

Users who are viewing this thread

Back
Top Bottom