Option Groups & Print Command

S

SamDev

I have several option groups on a form and a command button that prints the
corresponding report. I want to make sure the user selects an option from
each group before the report prints. Ideally, I would like if the user
missed selected an option from one or more the groups that when the print
button was pressed a warning box would appear. If all groups had a selection
than clicking the print button would print the report.

Any ideas? Thx.
 
D

Dirk Goldgar

SamDev said:
I have several option groups on a form and a command button that
prints the corresponding report. I want to make sure the user selects
an option from each group before the report prints. Ideally, I would
like if the user missed selected an option from one or more the
groups that when the print button was pressed a warning box would
appear. If all groups had a selection than clicking the print button
would print the report.

Any ideas? Thx.

Here's a simple example:

'----- start of example code -----
Private Sub cmdPrint_Click()

With Me!OptionGroup1
If IsNull(.Value) Then
MsgBox "Please select an option from Group1."
.SetFocus
Exit Sub
End If
End With

With Me!OptionGroup2
If IsNull(.Value) Then
MsgBox "Please select an option from Group2."
.SetFocus
Exit Sub
End If
End With

' ... et cetera ...

DoCmd.OpenReport "MyReport"

End Sub
'----- end of example code -----
 
S

SamDev

I have tried this and it still prints the report even when I have not
selected an option from each group. Maybe I'm naming the group incorrectly.
I right-mouse click on the frame of the group and use the label that is the
"Name" . Is that correct? For example if the Name is "Score1" the code would
read:

With Me!Score1
If IsNull(.Value) Then
MsgBox "Please select an option from Score1."
.SetFocus
Exit Sub

etc.....

???

Thx!!
 
D

Dirk Goldgar

SamDev said:
I have tried this and it still prints the report even when I have not
selected an option from each group. Maybe I'm naming the group
incorrectly. I right-mouse click on the frame of the group and use
the label that is the "Name" . Is that correct? For example if the
Name is "Score1" the code would read:

With Me!Score1

etc.....

???

Yes, that's correct. If it's not working with that code, could it be
that the field has a default value? If it has a default value, then it
won't be Null and you won't get the message, nor will the procedure be
exited early.
 
S

SamDev

I have removed the default values and still it prints when I don't have a
selection choosen in a group. I'm at a loss - any other ideas or
suggestions.

Thx,
 
D

Dirk Goldgar

SamDev said:
I have removed the default values and still it prints when I don't
have a selection choosen in a group. I'm at a loss - any other ideas
or suggestions.

Did you remove the default values both from the table fields and from
the option group controls? When you look at the form before clicking
the button, does it show any selections in the option groups?

Please copy and paste the complete code from the command button into a
reply to this message. Maybe there's some problem with the code that I
can't see from your snippet.
 
S

SamDev

Hi - Below is the code - any help would be appreciated. I experimented with
creating a new form and still have no luck.

Thx!!!

Private Sub Print_Click()
With Me!JumpsScore
If IsNull(.Value) Then
MsgBox "Please select score for Jumps."
.SetFocus
Exit Sub
End If
End With

With Me!Spins
If IsNull(.Value) Then
MsgBox "Please select score for Spins."
.SetFocus
Exit Sub
End If
End With

With Me!FieldMoves
If IsNull(.Value) Then
MsgBox "Please select score for Field Moves."
.SetFocus
Exit Sub
End If
End With

If Forms![Skaters]![Level Type] = 3 Then DoCmd.RunMacro "Print Pair
Event"
If Forms![Skaters]![Level Type] = 1 Then DoCmd.RunMacro "Print Single
Event"
If Forms![Skaters]![Level Type] = 2 Then DoCmd.RunMacro "Print Dance
Event"
End Sub
 
D

Dirk Goldgar

SamDev said:
Hi - Below is the code - any help would be appreciated. I
experimented with creating a new form and still have no luck.

Thx!!!

Private Sub Print_Click()
With Me!JumpsScore
If IsNull(.Value) Then
MsgBox "Please select score for Jumps."
.SetFocus
Exit Sub
End If
End With

With Me!Spins
If IsNull(.Value) Then
MsgBox "Please select score for Spins."
.SetFocus
Exit Sub
End If
End With

With Me!FieldMoves
If IsNull(.Value) Then
MsgBox "Please select score for Field Moves."
.SetFocus
Exit Sub
End If
End With

If Forms![Skaters]![Level Type] = 3 Then DoCmd.RunMacro "Print
Pair Event"
If Forms![Skaters]![Level Type] = 1 Then DoCmd.RunMacro "Print
Single Event"
If Forms![Skaters]![Level Type] = 2 Then DoCmd.RunMacro "Print
Dance Event"
End Sub

Dirk Goldgar said:
Did you remove the default values both from the table fields and from
the option group controls? When you look at the form before clicking
the button, does it show any selections in the option groups?

Please copy and paste the complete code from the command button into
a reply to this message. Maybe there's some problem with the code
that I can't see from your snippet.

I don't see anything wrong with that code, so -- assuming this is the
code being executed, and unless I've overlooked something -- it must be
that these option groups aren't Null. Are these controls bound or
unbound? To see what's going on, set a breakpoint on the Sub header
line and step through the code when the button is clicked. Check the
value of the option group as each " If IsNull(.Value) Then" statement is
executed. That may reveal something.
 
S

SamDev

Thank YOU, thank you!!! It is NOW working!!! You are terrific!!!


Dirk Goldgar said:
SamDev said:
Hi - Below is the code - any help would be appreciated. I
experimented with creating a new form and still have no luck.

Thx!!!

Private Sub Print_Click()
With Me!JumpsScore
If IsNull(.Value) Then
MsgBox "Please select score for Jumps."
.SetFocus
Exit Sub
End If
End With

With Me!Spins
If IsNull(.Value) Then
MsgBox "Please select score for Spins."
.SetFocus
Exit Sub
End If
End With

With Me!FieldMoves
If IsNull(.Value) Then
MsgBox "Please select score for Field Moves."
.SetFocus
Exit Sub
End If
End With

If Forms![Skaters]![Level Type] = 3 Then DoCmd.RunMacro "Print
Pair Event"
If Forms![Skaters]![Level Type] = 1 Then DoCmd.RunMacro "Print
Single Event"
If Forms![Skaters]![Level Type] = 2 Then DoCmd.RunMacro "Print
Dance Event"
End Sub

Dirk Goldgar said:
I have removed the default values and still it prints when I don't
have a selection choosen in a group. I'm at a loss - any other ideas
or suggestions.

Did you remove the default values both from the table fields and from
the option group controls? When you look at the form before clicking
the button, does it show any selections in the option groups?

Please copy and paste the complete code from the command button into
a reply to this message. Maybe there's some problem with the code
that I can't see from your snippet.

I don't see anything wrong with that code, so -- assuming this is the
code being executed, and unless I've overlooked something -- it must be
that these option groups aren't Null. Are these controls bound or
unbound? To see what's going on, set a breakpoint on the Sub header
line and step through the code when the button is clicked. Check the
value of the option group as each " If IsNull(.Value) Then" statement is
executed. That may reveal something.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 

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