[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

VB input box query

Posted on 2002-07-11
8
Medium Priority
?
338 Views
Last Modified: 2010-07-27
how to determine whether a user has clicked the OK or CANCEL button in an input box in VB?
0
Comment
Question by:ganpat
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 7145962
if the user clicks cancel, the function returns an empty string. Unfortunately, if the user clicks ok with empty field the same...
cheers
0
 
LVL 3

Expert Comment

by:sanjaykattimani
ID: 7145987
There is no 100% precise way to find whether Ok or cancel button was clicked. Following code works but fails if user removes the contents of the input box and click Ok.

If InputBox("Checking inputbox", "Sample Title", "DefalultValue") = "" Then
    MsgBox "Cancel clicked", vbInformation
Else
    MsgBox "Value entered", vbInformation
End If

Alternate is to use your own form which resembles input box and can works 100% as you wish.

Good luck
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7146692
Following previous comments, you could do this: (You ALWAYS need to check what value is returned)

Private Sub Form_Click()
Dim s As String

s = InputBox("Checking inputbox", "Sample Title", "DefalultValue")
If s <> "" And s <> "DefalultValue" Then
   ' what you need with string returned
   Debug.Print s
End If
End Sub
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Accepted Solution

by:
Monchanger earned 200 total points
ID: 7147388
I found this snippet which was written by Bill McCarthy of Barongarook, Victoria, Australia :

Ascertain OK or Cancel From InputBox
When the user presses Cancel on a VB InputBox, the string
returned is a vbNullString. If the user inputs a zero-length string and presses OK, the return string is empty (""). Unfortunately, in VB, you can’t compare an empty string to vbNullString because VB equates "" to be equal to vbNullString even though the two are quite different.
However, you can use the undocumented StrPtr function to
determine whether the return string is indeed a vbNullString. A vbNullString’s pointer is, by definition, zero:

[I added to the code a little:]
Dim strReturn as String
strReturn = InputBox("Enter in a value")
If StrPtr(strReturn) = 0 Then
   msgbox "User pressed Cancel"
Elseif strReturn="" then
   msgbox "User entered blank string"
Else
   msgbox "User entered: " & strReturn
End If
0
 

Author Comment

by:ganpat
ID: 7148291
Thanks a tonne!
0
 

Expert Comment

by:phanikishore
ID: 8604905
HI this is from kishore

this is my vb code

Dim a As Date
Dim b As Date

a = InputBox("Enter the Start Date", "Start Date")
b = InputBox("Enter the End Date", "End Date")

actually i want to generate a data report in vb based on date format i am giving two input boxes for taking starting date

and ending date my problem is the input box taking string and any date format so i want to restrict the input box with only

date format.

Regards
kishore
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 8605715
You could check the return value with Isdate function and act accordingly.
0
 

Expert Comment

by:phanikishore
ID: 8611815
HI its fine for cheaking date

i am able to connect from vb to Oracle using ADODB1 Control but according present requirement

i want to connect to MsAccess and i the data should store in .mdb file ofter clicking add and

can any body help in this

connect VB with  Ms-Acess using ADODB1 Control

and how to add records

regards

kishroe.k
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question