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?
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With