Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default Help with if elseif verification

I am having difficulty with my code. I have a userform with several
textboxes. The user enters the number of cashiers into txtQty.
txtCnt is the number of cashiers actually listed. I want to check to
make sure the number of cashiers entered does not exceed the actual
number of cashiers. if it does a message box displays the
difference. If not it continues on with the rest of the code. I put
in the MsgBox " its not working" to help test. the code works as
designed unless txtQty is 10 or over regardless of the value of
txtCnt.


If Not IsNumeric(txtQty.Value) Then
MsgBox "Please enter a cashier number"
Exit Sub
ElseIf txtQty.Value txtCnt.Value Then
MsgBox txtQty.Value - txtCnt.Value

Exit Sub

ElseIf txtQty.Value 10 Then
Dim Msg, Style, Title, Help, Ctxt, Response, MyString
Msg = "You chose " & txtQty.Value & " cashiers. Is this correct?"
Style = vbYesNo + vbCritical + vbDefaultButton2
Title = "Verify Input"
Response = MsgBox(Msg, Style, Title, Help, Ctxt)
If Response = vbNo Then
MsgBox "Please re-enter the correct number of cashiers"
Exit Sub
Else: GoTo x
End If
Else: MsgBox " its not working"
Exit Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Help with if elseif verification

Just a suggestion...

If you indent your code and use block If/Then/Else, it may be easier to
read/debug your code.

Depending on where that X label is, you may not even need it. Your code could
just follow that path.


Dim Msg, Style, Title, Help, Ctxt, Response, MyString
If Not IsNumeric(txtQty.Value) Then
MsgBox "Please enter a cashier number"
Exit Sub
ElseIf txtQty.Value txtCnt.Value Then
MsgBox txtQty.Value - txtCnt.Value
Exit Sub
ElseIf txtQty.Value 10 Then
Msg = "You chose " & txtQty.Value & " cashiers. Is this correct?"
Style = vbYesNo + vbCritical + vbDefaultButton2
Title = "Verify Input"
Response = MsgBox(Msg, Style, Title, Help, Ctxt)
If Response = vbNo Then
MsgBox "Please re-enter the correct number of cashiers"
Exit Sub
Else
GoTo x
End If
Else
MsgBox "its not working"
Exit Sub
End if

stewart wrote:

I am having difficulty with my code. I have a userform with several
textboxes. The user enters the number of cashiers into txtQty.
txtCnt is the number of cashiers actually listed. I want to check to
make sure the number of cashiers entered does not exceed the actual
number of cashiers. if it does a message box displays the
difference. If not it continues on with the rest of the code. I put
in the MsgBox " its not working" to help test. the code works as
designed unless txtQty is 10 or over regardless of the value of
txtCnt.

If Not IsNumeric(txtQty.Value) Then
MsgBox "Please enter a cashier number"
Exit Sub
ElseIf txtQty.Value txtCnt.Value Then
MsgBox txtQty.Value - txtCnt.Value

Exit Sub

ElseIf txtQty.Value 10 Then
Dim Msg, Style, Title, Help, Ctxt, Response, MyString
Msg = "You chose " & txtQty.Value & " cashiers. Is this correct?"
Style = vbYesNo + vbCritical + vbDefaultButton2
Title = "Verify Input"
Response = MsgBox(Msg, Style, Title, Help, Ctxt)
If Response = vbNo Then
MsgBox "Please re-enter the correct number of cashiers"
Exit Sub
Else: GoTo x
End If
Else: MsgBox " its not working"
Exit Sub


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Help with if elseif verification

Stewart,
I removed some "dots" to test this without a form. The following seems to
work. Hope this helps.
Chris

Sub Hmm()

Dim Msg, Style, Title, Response
Dim txtQtyValue As Integer
Dim txtCntValue As Integer
txtQtyValue = 11
txtCntValue = 15

x:
' Code to get new value.
'
'...

If Not IsNumeric(txtQtyValue) Then
MsgBox "Please enter a cashier number"
Exit Sub
ElseIf txtQtyValue txtCntValue Then
MsgBox txtQtyValue - txtCntValue
Exit Sub
ElseIf txtQtyValue 10 Then
Msg = "You chose " & txtQtyValue & " cashiers. Is this correct?"
Style = vbYesNo + vbCritical + vbDefaultButton2
Title = "Verify Input"
Response = MsgBox(Msg, Style, Title)
If Response = vbNo Then
MsgBox "Please re-enter the correct number of cashiers"
Exit Sub
Else
GoTo x
End If
Else
MsgBox " its not working"
Exit Sub
End If

End Sub

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
Elseif? ibrokit Excel Worksheet Functions 5 November 25th 08 04:28 PM
elseif Tom Ogilvy Excel Programming 3 March 28th 07 03:03 AM
IF..Then..ELSE.. ELSEIF ole_ Excel Programming 4 April 20th 05 03:59 PM
If, ElseIf mast Excel Programming 1 January 26th 05 12:11 PM
If...Elseif...End If javab98 Excel Programming 2 July 19th 04 07:23 PM


All times are GMT +1. The time now is 08:47 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"