Looping / Branching Problem With Subs and Calls?

JimEoff

New Member
Joined
Aug 1, 2011
Messages
1
The code below is for a user scanning in barcodes for customer orders to be shipped. I'm using Excel 2010 in Windows 7.

Notice that the two subs have calls to each other, which may be the problem but I'm not very knowledgeable.

My specific problem is seen if you run the macro MyInputBox3 and:

1) Click OK in the (Action?) InputBox (without typing any data in)
2) Click through (OK) the MsgBox that arises ("Please scan (or enter) the next item...")
3) This time (the InputBox reappers) enter a number in the box and click OK
4) The resulting message box shows the value that was entered, which is as planned (in my actual macro the data will be used instead of displayed in the MsgBox), but then
5) A MsgBox displays says that the data entered is "Enter your input text HERE". (If you do steps 1 and 2 a few times it will display once for each time.)

What I'm wanting to happen is for the TryAgain sub to prompt the user to enter proper data (if he accidently click OK on the InputBox before entering data), and not get the extraneous message box.

Thanks

Code:
Public Sub MyInputBox3()

Dim MyInput
    MyInput = InputBox("Scan the next barcode, or type Quit", _
    "Action?", "Enter your input text HERE")

If MyInput = "Enter your input text HERE" Or _
MyInput = "" Then
Call TryAgain
End If

MsgBox "The text from MyInputBox is " & MyInput

End Sub


Public Sub TryAgain()
MsgBox "Please scan (or enter) the next item, or type Quit (after clicking OK)"
Call MyInputBox3
End Sub
 
Last edited:

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Maybe a "Do loop"?

Gary

Code:
Public Sub MyInputBox3()

Dim MyInput

Do
    MyInput = InputBox("Scan the next barcode, or type Quit", _
    "Action?", "Enter your input text HERE")
    If UCase(MyInput) = "QUIT" Then Exit Do
    
Loop Until MyInput <> "Enter your input text HERE" And MyInput <> ""

MsgBox "The text from MyInputBox is " & MyInput

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,584
Messages
6,179,687
Members
452,938
Latest member
babeneker

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top