Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Correct code to Exit Userform, with out Unloading data Corey Excel Programming 13 January 8th 07 12:25 AM
Getting error unloading Userform?? Ed Excel Programming 3 July 1st 05 12:27 AM
Unloading UserForm not working Marston Excel Programming 2 August 17th 04 04:18 AM
Unloading userform in MSComm event Sunny[_4_] Excel Programming 0 June 10th 04 06:04 PM
Not Unloading a UserForm Mike[_49_] Excel Programming 1 January 29th 04 11:45 PM


All times are GMT +1. The time now is 08:02 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"