Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trouble with InputBoxes

I'm currently working with InputBoxes in MS Access VBA. I'm examining validation and handling how the user interacts with the InputBox through pressing the OK or Cancel buttons.

Correct me if I'm wrong but InputBoxes can return any data type and by default return a string? For example:

Dim userInputValue As String

'Text to display, Title, Default Value
userInputValue = InputBox("Please enter a #", "Determine Limit", 10000)

If userInputValue = "" Then
    MsgBox ("You pressed the cancel button...")
End If

If the user presses the Cancel button this will run fine.

But when I swap this for an integer value like so:

Dim userInputValue As Integer
'Text to display, Title, Default Value
userInputValue = InputBox("Please enter a #", "Determine Limit", 10000)

If userInputValue = 0 Then
    MsgBox ("You pressed the cancel button...")
End If

I receive a Type Mismatch: Runtime Error '13' Why is this? When I debug the code and look at what is being returned I find that the userInputValue is actually 0, which is what I'm checking for. So is the problem that the InputBox is actually returning a string?

like image 516
Katana24 Avatar asked Apr 17 '13 13:04

Katana24


People also ask

How do you get chips inside the input box?

Create a wrapper <div> or any container that can container your chips and your input. and then style it like an input, usually putting a border would do.

How do you set focus on input field?

To set focus to an HTML form element, the focus() method of JavaScript can be used. To do so, call this method on an object of the element that is to be focused, as shown in the example. Example 1: The focus() method is set to the input tag when user clicks on Focus button.


1 Answers

Here is a way to catch most outcomes of interacting with the dialog;

Dim value As String
value = InputBox("Please enter a #", "Determine Limit", 10000)

If (StrPtr(value) = 0) Then
    MsgBox "You pressed cancel or [X]"

ElseIf (value = "") Then
    MsgBox "You did not enter anything"

ElseIf (Val(value) = 0 And value <> "0") Then
    MsgBox "Invalid number"

Else
    MsgBox "You entered " & value

End If
like image 135
Alex K. Avatar answered Oct 18 '22 15:10

Alex K.