InputBox Cancel

I created an input field to enter the username, but clicked the cancel button

Private Sub Form_Load()
fsUserName = UCase(InputBox("Please Enter your name.", "User Name", _
"dc"))

If fsUserName = "" Then
MsgBox "No name Entered." & Chr(13) & Chr(13) & _
"You must enter a name.", vbExclamation, "ERROR"
Form_Load
ElseIf VarType(fsUserName) = 0 Then 'If cancel clicked
cmdQuit_Click

End If

There is also a way when cmdQuit_Click is executed when the X button is clicked on the form, so if the user invokes the Command Quit or X button, the Quit script is launched. The quit script has a box message and a cleanup.

+3
source share
4 answers

You can use StrPtr()to determine if a trip has been pressed;

Dim fsUserName As String

fsUserName = InputBox("Please Enter your name.", "User Name", "dc")

If (StrPtr(fsUserName) = 0&) Then
    MsgBox "Cancelled or X clicked"
ElseIf fsUserName = "" Then
    MsgBox "No name Entered." & vbCr & "You must enter a name.", vbExclamation, "ERROR"
Else
    fsUserName = UCase$(fsUserName)
    MsgBox fsUserName
End If

- , , Form_Unload Form_QueryUnload, .
, (UnloadMode 0, X)

"Unload Me" .

: Form_Load Form_Load , .

+11

Alex StrPtr, , , , , , (IMO) , InputBox. , , , , , , .

, , .

+2

Excel InputBox Application.InputBox - .

Sub GetValue2()
    Dim Monthly As Variant
    Monthly = Application.InputBox _
        (Prompt:="Podaj wysokość miesięcznej wypłaty:", _
         Type:=1)
    If Monthly = False Then Exit Sub
    MsgBox "Zarobki rocznie: " & Monthly * 12
End Sub
0

...

Name = Application.InputBox( " " )

Name = "False"

MsgBox " "

Sub

0

Source: https://habr.com/ru/post/1751878/


All Articles