Option Groups Select case

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I have an option group (frClients) on an Access form which I call up from a
command button (PrintTime-sheets). On selection of option button (option24)
labelled "SBSA" I want to open and print a report named "rptSBSA" from code.
I have 16 different option buttons in the option group. I have tried the
following code but it does not print the report - can anyone tell me why or
what is missing from the code?

Private Sub PrintTime_sheets_Click()

Dim lngViolet As Long
frClients.Visible = True

Select Case Me!frClients
Case 1
lngViolet = RGB(128, 0, 128)
Me!SBSA.ForeColor = lngViolet
DoCmd.OpenReport "rptSBSA"
Case 2
lngViolet = RGB(128, 0, 128)
Me!DevBank.ForeColor = lngViolet
DoCmd.OpenReport "rptDevBank"
Case 3
lngViolet = RGB(128, 0, 128)
Me!DevBank.ForeColor = lngViolet
DoCmd.OpenReport "rptDevBank
End Select
End sub
 
Are you sure the code is running?

Kill two birds with one stone, and put MsgBox Me!frClients in that routine
just before the Select Case statement. Does the message box appear? Do you
get the value you're expecting in the message box?
 
Hi Douglas

When I put MsgBox Me fr!Clients before the select case I get error "Invalid
use of Null". When I put MsgBox "Hello" the message appears as expected?
 
That implies that frClients hasn't been set up properly.

How did you create it? Did you use the wizard?

You might try recreating it and see whether the code works the second time.
 
I created the frClients option group using the wizard.

When I use the same code individually in each option button's "Got Focus"
event all of the reports get called up and are printed, but only if I select
each button sequentially. As soon as I select option buttons randomly I get
the error "The option report action was cancelled".

I recreated a new option group but still experience the same problem. Is the
problem not in the way I need to declare the select case? Using the code
below I still get the "Invalid use of Null" error prior to the Select
statement.

Private Sub PrintTime_sheets_Click()
Dim x As OptionGroup
Set x = Me!frClients
Dim lngViolet As Long
lngViolet = RGB(128, 0, 128)
frClients.Visible = True

MsgBox Me.frClients
Select Case x
Case 1
Option22.SetFocus
Me!AfricanBank.ForeColor = lngViolet
DoCmd.OpenReport "rptAfrican Bank", acNormal, PrintMode
DoCmd.PrintOut "rptAfrican Bank"
DoCmd.Close acQuery, "qryAfrican Bank"
Case 2
Option24.SetFocus
Me!DevBank.ForeColor = lngViolet
DoCmd.OpenReport "rptDev Bank"
DoCmd.Close acQuery, "qryDev Bank"
End select
End sub
 
Thanks for your help Douglas. I found the problem using the message box that
you suggested. The code was in the click event of the Print-Time-sheets
command button, whereas it should have been in the click event of the
frClients option group.
 
Back
Top