VBA to open report based on listbox dropdown and button click (1 Viewer)

penchalas

Registered User.
Local time
Today, 22:56
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
 

Cronk

Registered User.
Local time
Tomorrow, 03:26
Joined
Jul 4, 2013
Messages
2,771
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
 

Minty

AWF VIP
Local time
Today, 18:26
Joined
Jul 26, 2013
Messages
10,367
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
 

penchalas

Registered User.
Local time
Today, 22:56
Joined
May 14, 2019
Messages
26
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 :):)
 

Minty

AWF VIP
Local time
Today, 18:26
Joined
Jul 26, 2013
Messages
10,367
Yes but its not as easy for end users to see / use.
 

Users who are viewing this thread

Top Bottom