Solved Assigning a label name to a variable (1 Viewer)

JMZ

New member
Local time
Today, 10:29
Joined
Nov 20, 2020
Messages
12
I have an Option Group with 7 Radial Buttons and the label is the name of a different report for each button.
I am using Case Statements for each button and what I would like to do is have each Case Statement look for the label name and place it in the DoCmd that opens the report for preview. What I have working now is nice, but, I have to hard code the report name in the DoCmd line.
Like this:
Case 1
(DoCmd.OpenReport "Report Name1", acViewPreview)

Any ideas on how this can be done?
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 15:29
Joined
Jul 9, 2003
Messages
16,245
If you see my blog here:-



There's a video demonstrating how to change the colour of a label in an option group.

However, I also demonstrate how to extract the label caption and place it in a table. I think you should be able to adapt my code to your particular problem.

If you want a free copy of the code, let me know and I will explain how you can get a free copy.
 

Cronk

Registered User.
Local time
Tomorrow, 02:29
Joined
Jul 4, 2013
Messages
2,770
You haven't given the names of your option labels, but assuming they are Label1, Label2 etc and the name of the Option group is Frame1, then you could open the corresponding report with
Code:
DoCmd.OpenReport me("Label"& me.Frame1).caption, acViewPreview)

This way you do not need the Select Case You'll need to insert square brackets if the report name has any spaces.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 15:29
Joined
Sep 12, 2006
Messages
15,614
You could have a table storing the mapping of the option button to the report name, or even use an external text file a user could edit for himself..

In all seriousness, why would the report change at runtime? If this is a general purpose report manager, then maybe you could pass in an array of button settings. That merely moves the problem to a different place, which might help. It seems to me it ends up either being a hard coded solution, or a flexible solution which needs an external place to store the options.
 

JMZ

New member
Local time
Today, 10:29
Joined
Nov 20, 2020
Messages
12
Thanks for the help, everyone.

Sorry for the CrossPost, didn't realize I did that.
 

JMZ

New member
Local time
Today, 10:29
Joined
Nov 20, 2020
Messages
12
You haven't given the names of your option labels, but assuming they are Label1, Label2 etc and the name of the Option group is Frame1, then you could open the corresponding report with
Code:
DoCmd.OpenReport me("Label"& me.Frame1).caption, acViewPreview)

This way you do not need the Select Case You'll need to insert square brackets if the report name has any spaces.
Cronk, your line of code was close, I made a change and it works great. It looks at the Report Name beside the button and prints that Report and the same for the other buttons with different Report Names.

Now I'm off to finish it, by setting up an Admin Form where I can add or replace reports. Then with a combo box showing all reports and selecting a new report, it will change the Label Caption of an old report.

Thank you for the code.

Code:
 DoCmd.OpenReport Me.Label1.Caption, acViewNormal
 

Cronk

Registered User.
Local time
Tomorrow, 02:29
Joined
Jul 4, 2013
Messages
2,770
Glad you got your solution. My code was based on the use of an option group as you mentioned in your original post. The use of a combo or list box (single or multiselect) lends itself to having the report names in a table as has been suggested by others above.

Incidentally, there is no problem in cross posting as long as you indicate this. The issue is where the cross posting is not known and people spend unnecessary time trying to provide solutions to an issue that has already been solved.
 

JMZ

New member
Local time
Today, 10:29
Joined
Nov 20, 2020
Messages
12
Glad you got your solution. My code was based on the use of an option group as you mentioned in your original post. The use of a combo or list box (single or multiselect) lends itself to having the report names in a table as has been suggested by others above.

Incidentally, there is no problem in cross posting as long as you indicate this. The issue is where the cross posting is not known and people spend unnecessary time trying to provide solutions to an issue that has already been solved.
I have something like that on another form but instead of a table, I just use MsysObjects in a SQL Select on the Combo Box RowSource and it list all Reports. Just select a report in the Combo Box and tap the command button to print.

I had not used an Option Group before and while I was creating new forms I wanted to include one. Now I got all kinds of ideas for it.

Thanks again

Code:
 SELECT [Name] FROM MSysObjects WHERE [Type] =-32764 AND Left([Name],1) <> "~" ORDER BY [Name];
 

Users who are viewing this thread

Top Bottom