PC Review


Reply
Thread Tools Rate Thread

Conditional Unloading of a Userform (I've got in a right pickle)

 
 
=?Utf-8?B?TWFyayBEdWxsaW5naGFt?=
Guest
Posts: n/a
 
      3rd Mar 2007
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 With Quote
 
 
 
 
Doug Glancy
Guest
Posts: n/a
 
      3rd Mar 2007
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" <(E-Mail Removed)> wrote in
message news:802DAB66-9981-4353-B0EC-(E-Mail Removed)...
> 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 With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      3rd Mar 2007
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" <(E-Mail Removed)> wrote in
message news:802DAB66-9981-4353-B0EC-(E-Mail Removed)...
> 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 With Quote
 
=?Utf-8?B?TWFyayBEdWxsaW5naGFt?=
Guest
Posts: n/a
 
      4th Mar 2007
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" <(E-Mail Removed)> wrote in
> message news:802DAB66-9981-4353-B0EC-(E-Mail Removed)...
> > 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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Correct code to Exit Userform, with out Unloading data Corey Microsoft Excel Programming 13 8th Jan 2007 12:25 AM
Getting error unloading Userform?? Ed Microsoft Excel Programming 3 1st Jul 2005 12:27 AM
Unloading UserForm not working Marston Microsoft Excel Programming 2 17th Aug 2004 04:18 AM
Unloading userform in MSComm event Sunny Microsoft Excel Programming 0 10th Jun 2004 06:04 PM
Not Unloading a UserForm Mike Microsoft Excel Programming 1 29th Jan 2004 11:45 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:01 PM.