Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

option group 1

Status
Not open for further replies.

shaminda

Programmer
Jun 9, 2000
170
US
I have two command buttons, (cmd1 and cmd2) 5 reports, and 5 option buttons on a option group named
option1
option2
option3
option4
option5
If the user selects option1 and press cmd1 I need to preview report1 if the user selects option1 and cmd2 I have to print report1. The same for rest of the options. How do I code this or reference the option buttons?
 
The Option Gropu will only return the value of the selected option. You often need to set the value for the individual option buttons to be different (1 through 5?). Then code a functio (or Sub) which accepts two arguments (Cmd as string, Opt As Integer). Each of the command buttons should call the Function/Sub with the appropiate argument ("Preview" or "Print") and the OptionGroup.Value. Use the cmd argument to decide on to use acPreview, or acNormal for the preview argument.

Place a single select case statement in the Module:

If (Cmd = "Preview") then
[tab]MyView = acPreview
Else
[tab]MyView = acNormal
EndIf

Select Case Opt

[tab]Case is = 1
[tab][tab]DoCmd.OpenReport reportname1, MyView 'to do report 1

[tab]Case is = 2
[tab][tab]DoCmd ... 'to do report 2

[tab]Case is = 3
[tab][tab]DoCmd ... 'to do report 3

[tab]Case is = 4
[tab][tab]DoCmd ... 'to do report 4

[tab]Case is = 5
[tab][tab]DoCmd ... 'to do report 5

End Select


MichaelRed
mred@duvallgroup.com
There is never time to do it right but there is always time to do it over
 
Michael,
Very elegant solution!!(You're welcome Shaminda. . .) Would there be any gain in legibility and maintenance ease to use the select case to fill a string for the report name and then just have one docmd at the bottom with the two strings passed to it? Thanks for all the great examples you provide in the forum.
 
I considered suggesting this from the perspective of effiency, but rejected it - from that perspective. From the documentation perspective, I (personally) find little benefit, however this is much more in the realm of 'taste' or 'style' than 'help'.

I (personally) try to use a 'style guide' for my apps. this simply 'codifies' decisions like this one, and is generally intended to maintain a similarity of coding - to provide the legibility and ease of maintenance.



MichaelRed
mred@duvallgroup.com
There is never time to do it right but there is always time to do it over
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top