6 replies
by glen_mcleod
The quick answer is:
Unload [formname] (or "Unload Me" if it's the current form)
However, why don't you use the built-in MsgBox statement? It is dismissed automatically when a button is clicked.
Glen
by dcarrier
by bill_h
If you simply want to provide the user with information, use the MsgBox statement. For example:
MsgBox Prompt := "Test Message",Buttons := vbYesNo, Title := "This is only a test..."
This will cause a dialog box to display with a title of "This is only a test...", and containing the string "Test Message"", and a "Yes" and "No" button. If the user clicks on either button the message box dialog will close, *but* you will not be able to determine which button was clicked.
If you wish toknow *which* button was clicked, use the MsgBox function. For example:
Dim iResult As Integer
iResult = MsgBox(Prompt:="Test Message", Buttons:=vbYesNo, Title:="This is only a test...")
This will result in the display of the dialog box asdescribed above. The difference is that a value corresponding to the clicked button is now contained in the variable iResult (iResult will be set to 6 if the "Yes" button was clicked, or 7 if the "No" button was clicked).
The examples above use "named arguments", i.e. the Prompt argument is assigned the string "Test Message". If you use named arguments, the arguments may be in any order. You may also use "positional arguments" as follows:
iResult = MsgBox("Test Message", vbYesNo, "Thisis only a test...")
When you use positional arguments, they must be provided in the proper syntactical order (prompt, buttons, title, helpfile, context).
For further information, view your online help for MsgBox. It is also available on the 'net at:
http://msdn.microsoft.com/library/devprods/vs6/vbasic/vbenlr98/vafctmsgbox.htm
(If the URL above does not work, locate and remove any spaces inserted by the TechRepublic system.)
Hope this helps...
by bill_h
(Pursuant to our e-mail discussion...)
The following code will display a succession of message boxes as long as the user clicks on the "Yes" button; if the user clicks on a "No" button, they will be returned to the form containing CommandButton1.
Private Sub Command1_Click()
'This variable indicates which MsgBox button was clicked
Dim iResult As Integer
iResult = MsgBox(Prompt:="test box", Buttons:=4)
If iResult = vbYes Then
iResult = MsgBox("press no to close", Buttons:=4)
If iResult = vbYes Then
iResult = MsgBox("test 3", Buttons:=4)
If iResult = vbYes Then
MsgBox "test 4", Buttons:=4
End If
End If
End If
End Sub
Hope this helps...let me know if you have any more questions.
by dcarrier
by dcarrier
This discussion is closed to new replies.
Trending Software posts
Sort by Trending