Alan Jackson
Alan Jackson

Reputation: 7

I need to open a report from a set of similar reports based on a feild value in a form

I have a MS access data base which has a form from which I want to open a report. There is a choice of 26 reports which all have different name which is a numeric value eg 221.1, 221.2 113.3, etc etc. I have an unbound field in the form which adds the values of four other bound fields and returns a number which should match one of the report names. I have called this unbound field "report Name". I want to add a button that is pressed which opens a report that has the same name as the value in the "report name" field so that if the value is 221.1 it will open report named 221.1 and so on...

I am not used to coding in access and generally rely on the built in commands, macros, wizards etc but in this case I don't think there is a suitable "wizard" to use. Any ideas or help on how I can do this would be gratefully received. I am working in Access 2013 but the data base was written in 2007 and transferred over.

Upvotes: 0

Views: 29

Answers (1)

Erik A
Erik A

Reputation: 32642

You can get away with just a tiny bit of code in your button's click handler:

Private Sub MyButton_Click()
     DoCmd.OpenReport Me![report Name]
End Sub

Add the code just like adding an embedded macro, but by choosing Code Builder instead of Macro Builder. The first and last line should already be there.

Upvotes: 2

Related Questions