Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Controlling the InputBox? 1

Status
Not open for further replies.

danharman

Technical User
Apr 24, 2001
22
AU
Dear All,

Does anyone know how I can control the use of an InputBox when using VBA? For example, if the end-user enters data into the InputBox and hits the "OK" button, then I want to then call a particular sub-procedure (eg. continue with the application). If the end-user however decides to stop the procedure and hence hits the "Cancel" button, I want to be able to then call another different sub-procedure (ie. close the procdure altogether)? I can do this with Message Boxes but not with the inbuilt InputBox function, as I am not sure if you can define the vbButton controls? Any ideas?

Cheers,

DJH.
 
?

Code:
Dim sInput As String

sInput = InputBox$("enter data")

If StrPtr(sInput) = 0 Then
  MsgBox "you chose to cancel"
  ' call procedure if cancelled
Else
  MsgBox "you entered " & sInput
  ' call procedure if OK
End If
 

Or if you want to have several options below is a snippet that may help


Sub InpBox()
Dim Message, Title, Default, MyValue
Message = "Enter a value between 1 and 3" ' Set prompt.
Title = "InputBox Demo" ' Set title.
Default = "1" ' Set default.
' Display message, title, and default value.
MyValue = InputBox(Message, Title)
Select Case MyValue
Case 1

Case 2

Case 3

Case ""
'this is the cancel option


End Select

End Sub

Just copy this and pop it in a module

regards

Jo
 
thanks jo for your assistance - works fine!
djh
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top