Hi All,
How can I determine if the OK button or the CANCEL button was clicked in an INPUT BOX??
II have the following code and it does not appear to be working correctly.
SSNreplace = InputBox("Please enter the Member's SSN", "Update a SSN")
If SSNreplace = "" Then
MsgBox "No Number Entered. Please Try Again", vbCritical, "Update a SSN"
Else If InputBox("No Number Entered. Please Try Again", vbCritical, "Update a SSN") = vbCancel ThenEnd If
End If
The bolded code does not seem to do anything......
3 8945 JKing 1,206
Recognized Expert Top Contributor
As far as I know a zero length string is returned if the user clicks cancel. However the same is returned if they click OK and type nothing.
An example would be: -
Dim strTest As String
-
-
strTest = InputBox("Enter value:")
-
-
if strTest = "" Then
-
MsgBox "User clicked cancel or entered no data."
-
Else
-
MsgBox "You entered: " & strTest
-
End If
-
As far as I know a zero length string is returned if the user clicks cancel. However the same is returned if they click OK and type nothing.
An example would be: -
Dim strTest As String
-
-
strTest = InputBox("Enter value:")
-
-
if strTest = "" Then
-
MsgBox "User clicked cancel or entered no data."
-
Else
-
MsgBox "You entered: " & strTest
-
End If
-
With that in mind, how could I make the input box appear as long as no data is entered? Some kind of loop or test for data?? The way you have it now, the routine does a test then ends....I'm trying to make it so that if the user types nothing and clicks OK, the code would check for input, if it finds none, it would show a msg box stating no data entered and then show the input box again...If the user click Cancel, the routine ends.
ADezii 8,834
Recognized Expert Expert
Hi All,
How can I determine if the OK button or the CANCEL button was clicked in an INPUT BOX??
II have the following code and it does not appear to be working correctly.
SSNreplace = InputBox("Please enter the Member's SSN", "Update a SSN")
If SSNreplace = "" Then
MsgBox "No Number Entered. Please Try Again", vbCritical, "Update a SSN"
Else If InputBox("No Number Entered. Please Try Again", vbCritical, "Update a SSN") = vbCancel ThenEnd If
End If
The bolded code does not seem to do anything......
The bold code will never work since vbCancel is an Intrinsic Constant with a value of 2, and the return value of the InputBox() Function if the Cancel button is pressed is a Zero Length String (""). Try this code and see how you like it, it has been tested and is fully operational: - Dim SSNreplace, strMsg As String, intResponse As Integer, blnTryAgain As Boolean
-
-
strMsg = "You either Cancelled the previous operation or clicked on "
-
strMsg = strMsg & "the OK button with no value entered in the Text Field."
-
strMsg = strMsg & vbCrLf & vbCrLf & "Do you wish to try again?"
-
-
-
Do
-
SSNreplace = InputBox("Please enter the Member's SSN", "Update a SSN")
-
-
If SSNreplace = "" Then
-
intResponse = MsgBox(strMsg, vbQuestion + vbYesNo + vbDefaultButton2, "Update a SSN")
-
If intResponse = vbYes Then
-
blnTryAgain = True
-
Else
-
blnTryAgain = False
-
End If
-
Else
-
MsgBox "You have entered " & SSNreplace & " as your SSAN"
-
blnTryAgain = False
-
End If
-
Loop While blnTryAgain
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Jim Quast |
last post by:
I have an ASP page and a CREGReports002.vbs file coded to export data to
excel. I do this by building variables in a stored procedure. The ASP page
has text boxes, list boxes, and radio buttons. ...
|
by: Hans |
last post by:
Hi!
Does anybody of you have a good algorithm to capture when a value in a
textbox is changed? I'm using the keypress/keydown events but they seems to
be a bit inconsistent (IE and Mozilla)....
|
by: lkrubner |
last post by:
I've got a function, you can see it below, that is being called
onmouseup in the textarea on my main form. The idea is to find a
selection if possible and store that text in a global variable. I...
|
by: jva02 |
last post by:
Hi,
I'm confused why I can capture an event fired by an ActiveX object when
it's loaded via an <object> tag, but not when loaded using "new
ActiveXObject".
Here's a basic example:
vb ActiveX...
|
by: ewillyb |
last post by:
Hi,
ASP.NET has some interesting behavior when the user hits the Enter key.
If there are multiple ASP:Buttons (rendered as HTML submits) on the
form, when the user hits enter, the first button's...
|
by: Jake Barnes |
last post by:
I'm trying to learn AJAX so tonight I sat down and came up with a
little toy that I can do tests with. You can see it here:
http://www.publicdomainsoftware.org/ajaxExperiment.htm
I've got...
|
by: trbjr |
last post by:
Hello experts,
I want to describe a project design and then ask some questions at the end.
There is no code in this discussion, just symbols to illustrate an idea.
Let S stand for a screen...
|
by: Lit |
last post by:
Hi,
How can I capture the vertical scroll bar position for a Listbox.
I have a Listbox of 100 items + when I click on it I post back remove the
item selected.
After returning to the client...
|
by: Hirru |
last post by:
Hi.................,
i want to capture event from vb dll file in javascript,actually i can already access all the function of that dll from javascript but i don know how to capture event raised by...
|
by: destiny007 |
last post by:
can any one help me to write code to capture selected text from a page but problem is that i am not able to decide where to call the functio.in this case the function is called in all cases of mouse...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |