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
Solved

VB input box query

Posted on 2002-07-11
8
322 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
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 4

Accepted Solution

by:
Monchanger earned 50 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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 Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

789 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