Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Conditional Unloading of a Userform (I've got in a right pickle)
The Story so far!
I have a userform with 3 Command buttons and 2 toggle buttons. The 2 tog buts trigger an ontime event each in a standard mudule. this all works fine. 1 command button hides the userform and the other one, which is a cancel button is where I'm having a bit of a problem. What I want to happen is when clicked, the state of the 2 tog but are checked and if both are false, then unload the form. If either one or both are true then a message box pops up with do you want to continue with vbYes and vbNo buttons. If the user says yes then a sub is run to change tog buttons to false then the form unloads. If no is chosen then the msgbox diappears and the userform is left open. Hears what i have so far Private Sub CommandButton1_Click() On Error Resume Next MkDir "C:\AutoSaves" On Error GoTo 0 End Sub Private Sub CommandButton2_Click() 'Caption is Hide frmOptions.Hide End Sub Private Sub CommandButton3_Click() ' Caption is Cancel If frmOptions.ToggleButton1.Value = True Then ElseIf frmOptions.ToggleButton2.Value = True Then 'Can these to line be combine to give ' a boolean and argument Dim Msg, Style, Title, Response Msg = "Do you want to Cancel Auto Save ?" 'This bit all works fine Style = vbYesNo Title = "Cancel Auto Save Options" Response = MsgBox(Msg, Style, Title) If Response = vbYes Then ' User chose Yes. CancelToggles ' Run sub Else ' User chose No. Hide ' Hides the userform End If ' upto hear happens if either one or both the toggle buttons are true Else Unload Me 'I want the userform to unload if both togglr buttons are false End If End If End Sub Private Sub CancelToggles() ToggleButton1.Value = False ToggleButton2.Value = False End Sub Can normal ws funtions like AND and LOGICAL be call upon for something like this? Please help my brain is liquifying and draining out my ears! |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Conditional Unloading of a Userform (I've got in a right pickle)
Mark,
I think this is the general structure you are looking for?: frmOptions.ToggleButton1.Value = True Or frmOptions.ToggleButton2.Value = True Then ' code if either is true Else 'code if both are false endif hth, Doug "Mark Dullingham" wrote in message ... The Story so far! I have a userform with 3 Command buttons and 2 toggle buttons. The 2 tog buts trigger an ontime event each in a standard mudule. this all works fine. 1 command button hides the userform and the other one, which is a cancel button is where I'm having a bit of a problem. What I want to happen is when clicked, the state of the 2 tog but are checked and if both are false, then unload the form. If either one or both are true then a message box pops up with do you want to continue with vbYes and vbNo buttons. If the user says yes then a sub is run to change tog buttons to false then the form unloads. If no is chosen then the msgbox diappears and the userform is left open. Hears what i have so far Private Sub CommandButton1_Click() On Error Resume Next MkDir "C:\AutoSaves" On Error GoTo 0 End Sub Private Sub CommandButton2_Click() 'Caption is Hide frmOptions.Hide End Sub Private Sub CommandButton3_Click() ' Caption is Cancel If frmOptions.ToggleButton1.Value = True Then ElseIf frmOptions.ToggleButton2.Value = True Then 'Can these to line be combine to give ' a boolean and argument Dim Msg, Style, Title, Response Msg = "Do you want to Cancel Auto Save ?" 'This bit all works fine Style = vbYesNo Title = "Cancel Auto Save Options" Response = MsgBox(Msg, Style, Title) If Response = vbYes Then ' User chose Yes. CancelToggles ' Run sub Else ' User chose No. Hide ' Hides the userform End If ' upto hear happens if either one or both the toggle buttons are true Else Unload Me 'I want the userform to unload if both togglr buttons are false End If End If End Sub Private Sub CancelToggles() ToggleButton1.Value = False ToggleButton2.Value = False End Sub Can normal ws funtions like AND and LOGICAL be call upon for something like this? Please help my brain is liquifying and draining out my ears! |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Conditional Unloading of a Userform (I've got in a right pickle)
Mark,
As Doug said, an OR test is what you want. A couple of other things. When testing a control that returns a boolean, you don't need to test for true, that is saying iF TRUE = TRUE. In a form, you can refer to the generice object ME, avoiding spelling out the form name. And also, a bit of indenting will help to make it more readable Private Sub CommandButton3_Click() ' Caption is Cancel Dim Msg, Style, Title, Response If Me.ToggleButton1.Value Or _ Me.ToggleButton2.Value Then Msg = "Do you want to Cancel Auto Save ?" 'This bit all works fine Style = vbYesNo Title = "Cancel Auto Save Options" Response = MsgBox(Msg, Style, Title) If Response = vbYes Then CancelToggles Else Hide End If Else Unload Me End If End Sub -- --- HTH Bob (there's no email, no snail mail, but somewhere should be gmail in my addy) "Mark Dullingham" wrote in message ... The Story so far! I have a userform with 3 Command buttons and 2 toggle buttons. The 2 tog buts trigger an ontime event each in a standard mudule. this all works fine. 1 command button hides the userform and the other one, which is a cancel button is where I'm having a bit of a problem. What I want to happen is when clicked, the state of the 2 tog but are checked and if both are false, then unload the form. If either one or both are true then a message box pops up with do you want to continue with vbYes and vbNo buttons. If the user says yes then a sub is run to change tog buttons to false then the form unloads. If no is chosen then the msgbox diappears and the userform is left open. Hears what i have so far Private Sub CommandButton1_Click() On Error Resume Next MkDir "C:\AutoSaves" On Error GoTo 0 End Sub Private Sub CommandButton2_Click() 'Caption is Hide frmOptions.Hide End Sub Private Sub CommandButton3_Click() ' Caption is Cancel If frmOptions.ToggleButton1.Value = True Then ElseIf frmOptions.ToggleButton2.Value = True Then 'Can these to line be combine to give ' a boolean and argument Dim Msg, Style, Title, Response Msg = "Do you want to Cancel Auto Save ?" 'This bit all works fine Style = vbYesNo Title = "Cancel Auto Save Options" Response = MsgBox(Msg, Style, Title) If Response = vbYes Then ' User chose Yes. CancelToggles ' Run sub Else ' User chose No. Hide ' Hides the userform End If ' upto hear happens if either one or both the toggle buttons are true Else Unload Me 'I want the userform to unload if both togglr buttons are false End If End If End Sub Private Sub CancelToggles() ToggleButton1.Value = False ToggleButton2.Value = False End Sub Can normal ws funtions like AND and LOGICAL be call upon for something like this? Please help my brain is liquifying and draining out my ears! |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Conditional Unloading of a Userform (I've got in a right pickl
Thanks Chaps thats just what I needed.
For some reason I didn't think you could us the same argument structure in VBA as you do in a worksheet function, I thought it would be more complicated than that ! Mark "Bob Phillips" wrote: Mark, As Doug said, an OR test is what you want. A couple of other things. When testing a control that returns a boolean, you don't need to test for true, that is saying iF TRUE = TRUE. In a form, you can refer to the generice object ME, avoiding spelling out the form name. And also, a bit of indenting will help to make it more readable Private Sub CommandButton3_Click() ' Caption is Cancel Dim Msg, Style, Title, Response If Me.ToggleButton1.Value Or _ Me.ToggleButton2.Value Then Msg = "Do you want to Cancel Auto Save ?" 'This bit all works fine Style = vbYesNo Title = "Cancel Auto Save Options" Response = MsgBox(Msg, Style, Title) If Response = vbYes Then CancelToggles Else Hide End If Else Unload Me End If End Sub -- --- HTH Bob (there's no email, no snail mail, but somewhere should be gmail in my addy) "Mark Dullingham" wrote in message ... The Story so far! I have a userform with 3 Command buttons and 2 toggle buttons. The 2 tog buts trigger an ontime event each in a standard mudule. this all works fine. 1 command button hides the userform and the other one, which is a cancel button is where I'm having a bit of a problem. What I want to happen is when clicked, the state of the 2 tog but are checked and if both are false, then unload the form. If either one or both are true then a message box pops up with do you want to continue with vbYes and vbNo buttons. If the user says yes then a sub is run to change tog buttons to false then the form unloads. If no is chosen then the msgbox diappears and the userform is left open. Hears what i have so far Private Sub CommandButton1_Click() On Error Resume Next MkDir "C:\AutoSaves" On Error GoTo 0 End Sub Private Sub CommandButton2_Click() 'Caption is Hide frmOptions.Hide End Sub Private Sub CommandButton3_Click() ' Caption is Cancel If frmOptions.ToggleButton1.Value = True Then ElseIf frmOptions.ToggleButton2.Value = True Then 'Can these to line be combine to give ' a boolean and argument Dim Msg, Style, Title, Response Msg = "Do you want to Cancel Auto Save ?" 'This bit all works fine Style = vbYesNo Title = "Cancel Auto Save Options" Response = MsgBox(Msg, Style, Title) If Response = vbYes Then ' User chose Yes. CancelToggles ' Run sub Else ' User chose No. Hide ' Hides the userform End If ' upto hear happens if either one or both the toggle buttons are true Else Unload Me 'I want the userform to unload if both togglr buttons are false End If End If End Sub Private Sub CancelToggles() ToggleButton1.Value = False ToggleButton2.Value = False End Sub Can normal ws funtions like AND and LOGICAL be call upon for something like this? Please help my brain is liquifying and draining out my ears! |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Correct code to Exit Userform, with out Unloading data | Excel Programming | |||
Getting error unloading Userform?? | Excel Programming | |||
Unloading UserForm not working | Excel Programming | |||
Unloading userform in MSComm event | Excel Programming | |||
Not Unloading a UserForm | Excel Programming |