Message Boxes in VB

SteveC24

Registered User.
Local time
Today, 06:31
Joined
Feb 1, 2003
Messages
444
Hi,

I realise that this is an unbvelievably simple question, but I am an unbelieveably simple person!

How do I make a message box in VB? What are the different parameters you can use (e.g. vbOKOnly etc).

Thanks,
 
MsgBox "Put your message in here", msgbox type here, "msgbox title here"


When coding in VB, the IntelliSense system should give you all of the options.
 
OK, that works, but I can't figure out how to use VB to make a delete conformation message box.

I have figured out that I want to put the code in the "Before Del Confirm" property. But when I put the message box code in there, and run the form, I get the delete confirmation box I made, but even if I click "No", it deletes the record.

Help???

Thanks,
 
Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)
MsgBox "Do you want to delete the record? This is irreversible!", vbYesNo, "Warning!"
End Sub
 
You need to capture the return value from the MsgBox function

try:
Code:
Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer) 

dim iResponse as integer

iResponse = MsgBox "Do you want to delete the record? This is irreversible!", vbYesNo, "Warning!" 

If iResponse = vbYes then
     'Add you code to delete here
else
     Exit sub
end if

End Sub
 
How about...
Code:
    If MsgBox("Are you sure you want to delete the current record?", vbQuestion + vbYesNo, "Delete Current Record?") = vbYes Then
        DoCmd.RunCommand acCmdDeleteRecord [COLOR=red]'Access command to delete record[/COLOR] 
    Else
        MsgBox "Delete Function Aborted.", vbInformation
        Exit Sub
    End If
HTH
 

Users who are viewing this thread

Back
Top Bottom