I have created an Inputbox to get the username entered but stuck with 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
Also is there a way that when the X button on the form is clicked it executes cmdQuit_Click so that if the userclicks the command button Quit or X ,the Quit script is run.In the quit script there are message boxes and cleanup.
You can use
StrPtr()to detect if cancel was clicked;If you want to do something when the form unloads you can use the
Form_Unloadevent or better theForm_QueryUnloadevent which fires before the actual unload & allows you to cancel it.It will also tell you why the form is unloading (
UnloadModewill be 0 if the red X is clicked)Using “
Unload Me” will raise both of the events.Edit: Calling
Form_LoadinForm_Loadlike that will eventually fill up the stack, better to use a loop to look for a missing username.