Option group coding

E

Eric G

I've added an unbound Option group named SortBy to a form menu. with
its default value of 1.
The Option group has two options only, with the first option being the
default.

I've created four pairs of reports. Let's call them A1, A2, B1,B2
etc. I'd like to apply this one option group to these four pairs.

I just added the mate for each report. Previously I had the following
code open each of the four reports.

DoCmd.OpenReport "A1", acPreview
DoCmd.RunCommand acCmdFitToWindow

How would I now change the code so that when the button for report A
is selected and the option group is selecting Value 1 (default),
report A1 is opened?

Similarly how would I code to open report A2 when button A is selected
and option group option Value 2 is selected?

TIA Eric
 
J

Jonathan Parminter

Hi Eric, if I understand your post you want to determine
the report prefix with option group sortby and the report
name sufix with the second option group.

use the following as an example

dim strReport as string
dim strBeginPart as string
dim strEndPart as string

if SortBy=1 then
strBeginPart="A"
else
strBeginPart="B"
end if

if OtherOptionGroup=1 then
strEndPart="1"
else
strEndPart="2"
end if

if len(strBeginPart)<1 or len(strEndPart)<1 then
msgbox "You need to complete your selection..."
else
strReport=strBeginPart & strEndPart
docmd.openreport strReport
end if

Luck
Jonathan
 
N

Nick Coe

Eric,

Concatenate the option group value with a defined value in
the on_click event of each button.

If your option group is called grp1 and the buttons are
cmdA and cmdB:

Private Sub cmdA_Click

Dim strReportName as String

strReportName = "A" & Me.grp1

DoCmd.OpenReport strReportName etc etc etc

etc

Repeat for button B setting the value of strReport

strReportName = "B" & Me.grp1

If you've got a number of reports there may be a simpler
way to code it than repeating code for each on_click event.

Good luck

Nick Coe
Lincoln UK
Accessing for quite some time...
classicnick at yahoo dot com
 
E

Eric G

Hi Nick,

Thanks very much for your help!
I'm pleased to report it did the trick very nicely.

I have four pairs of reports so it's not too bad to repeat the code.

Thanks again, I appreciate it! Eric
 
E

Eric G

Hi Jonathan,
Hi Eric, if I understand your post you want to determine
the report prefix with option group sortby and the report
name sufix with the second option group.

Not quite. The prefix is determined by clicking on a command button.
It's just the suffix that would be determined by an option group.

I followed Nick's suggestion and it's worked out nicely with his code.
Thanks though for offering your help. I appreciate it.

Eric
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top