OptionButton linked with CommandButton

akhlaq768

Registered User.
Local time
Today, 10:31
Joined
Jan 17, 2008
Messages
42
I have a form that has two Option buttons (IP and OP),

And I have a command button which runs a macro which then displays a report.

How can I link the check boxes to the command button so that if 'IP' is selected then it should run Macro 1 and if 'OP' was selected then Macro 2 will run after the command buttons is pressed?

This is my code for the command button

Code:
Private Sub Command7_Click()
On Error GoTo Err_Command7_Click
If Nz(Me.SearchBox.Value, "") = "" Then
MsgBox "Please enter a unit numnber!"
Exit Sub
Else
 
Dim stDocName As String
If IP = True And OP = False Then
DoCmd.RunMacro "Macro1"
ElseIf OP = True And IP = False Then
DoCmd.RunMacro "Macro2"
ElseIf IP = True And OP = True Then
MsgBox "Check one option only"
Else
End If
 
End If
DoCmd.RunMacro stDocName
Exit_Command7_Click:
Exit Sub
Err_Command7_Click:
MsgBox Err.Description
Resume Exit_Command7_Click
 
End Sub

but when i run it, i get the following error....

'Object doesn't support this property or method'
 
First of all are your options buttons in an Option Group? By that I mean did you place two option buttons on the screen or did you use an object group control.

if the former then use an option group. Option groups one allow one selection, therefore you can examine the control to see which one has been chosen. Then you can code accordingly.

David
 

Users who are viewing this thread

Back
Top Bottom