option group in switchboard problem

thunderstorm

Registered User.
Local time
Today, 22:00
Joined
Jan 16, 2004
Messages
18
I am creating a switchboard for my database from stratch.
I wanted to have an option group, which I have created, and the options in it are the names of the forms in my database. I currently have it set up so that when the user clicks the option button, the form is opened immediately.
However, I wanted to have it so that when the option button (the circle) is clicked, a message box comes up confirming whether the user wants to go to the form or not. I.e. clicking cancel would return the user to the switchboard, and clicking OK would continue to the form.
How would I go about this?
Currently each option button is linked to a macro that opens each form.
 
thunderstorm said:
Currently each option button is linked to a macro that opens each form.

First off, ditch macros - they are EVIL! :cool:

thunderstorm said:
How would I go about this?

For a start I wouldn't use an option group and instead just create command buttons. These can then all be given their own "personality".

On the click of a command button (in it's OnClick() event - after selecting Code Builder from the ... button)

Code:
Private Sub MyCommandButton_Click()
    If MsgBox("Do you want to open this form?",vbQuestion + vbYesNo, "Open Form?") = vbYes Then
        DoCmd.Close acForm, Me.Name
        DoCmd.OpenForm "MyNextForm"
    End If
End Sub
 
thanks, i've tried this but i'm not too experienced with code, it is telling me that something is wrong with the following line

Private Sub Command2_Click()
 
Did you copy the complete code I posted above. You don't need to use the first or last line as that is created for you by Access. If so, delete those lines, and if not, post the complete code of the module...
 
Private Sub Command2_Click()
Private Sub MyCommandButton_Click()
If MsgBox("Do you want to open this form?", vbQuestion + vbYesNo, "Open Form?") = vbYes Then
DoCmd.Close acForm, Me.Name
DoCmd.OpenForm "Car"
End If
End Sub
End Sub
 
Code:
Private Sub Command2_Click()
    If MsgBox("Do you want to open this form?", vbQuestion + vbYesNo, "Open Form?") = vbYes Then
        DoCmd.Close acForm, Me.Name
        DoCmd.OpenForm "Car"
    End If
End Sub

The MyCommandButton_Click() line was an example to demonstrate the name of your command button; in this case Command2.

That'll do what you want for that command button.
 
okay, I have it working thank you for your help!
What would I need to do to stop it closing the switchboard once you press ok?:D
 
remove this line:

DoCmd.Close acForm, Me.Name



Sorry, it's just me preference to close forms, and that bit is coded without thinking.
 

Users who are viewing this thread

Back
Top Bottom