473,465 Members | 4,818 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to capture Input Box Button

132 New Member
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......
Jul 12 '07 #1
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:
Expand|Select|Wrap|Line Numbers
  1. Dim strTest As String
  2.  
  3. strTest = InputBox("Enter value:")
  4.  
  5. if strTest = "" Then
  6.      MsgBox "User clicked cancel or entered no data."
  7. Else
  8.      MsgBox "You entered: " & strTest
  9. End If
  10.  
Jul 12 '07 #2
Proaccesspro
132 New Member
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:
Expand|Select|Wrap|Line Numbers
  1. Dim strTest As String
  2.  
  3. strTest = InputBox("Enter value:")
  4.  
  5. if strTest = "" Then
  6.      MsgBox "User clicked cancel or entered no data."
  7. Else
  8.      MsgBox "You entered: " & strTest
  9. End If
  10.  

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.
Jul 12 '07 #3
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:
Expand|Select|Wrap|Line Numbers
  1. Dim SSNreplace, strMsg As String, intResponse As Integer, blnTryAgain As Boolean
  2.  
  3. strMsg = "You either Cancelled the previous operation or clicked on "
  4. strMsg = strMsg & "the OK button with no value entered in the Text Field."
  5. strMsg = strMsg & vbCrLf & vbCrLf & "Do you wish to try again?"
  6.  
  7.  
  8. Do
  9.   SSNreplace = InputBox("Please enter the Member's SSN", "Update a SSN")
  10.  
  11.   If SSNreplace = "" Then
  12.     intResponse = MsgBox(strMsg, vbQuestion + vbYesNo + vbDefaultButton2, "Update a SSN")
  13.       If intResponse = vbYes Then
  14.         blnTryAgain = True
  15.       Else
  16.         blnTryAgain = False
  17.       End If
  18.   Else
  19.     MsgBox "You have entered " & SSNreplace & " as your SSAN"
  20.     blnTryAgain = False
  21.   End If
  22. Loop While blnTryAgain
Jul 12 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
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. ...
7
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)....
9
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...
2
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...
5
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...
15
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...
6
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...
7
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...
9
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...
1
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...
1
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...
0
marktang
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,...
0
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...
0
Oralloy
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,...
1
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...
0
tracyyun
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...
0
agi2029
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,...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.