Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pop-up Message Box 1

Status
Not open for further replies.

achiola

MIS
Apr 26, 2001
44
US
Hi All,
I am trying to create a message box that will appear when a command button is clicked on. I want to write a warning before the user continues and then give the user two choices, continue "yes" or continue "no" in which case "yes" proceeds to perform the actions of the button while "no" simply closes it out. Any ideas about the best way to go about this. I already have the buttton on the Form. It is a button that appends a query.

Thanks,
Nino
 
Try this:

Dim intPress As Integer

intPress= MsgBox("text you want to appear in box",vbWarning + vbOKCancel,"Title of your message box")

If intPress = vbOK Then
DoCmd.OpenQuery"Name of your query"
End If

Hope this helps. If you want the buttons to say Yes and No instead of OK and Cancel then change the vbOKCancel to vbYesNo, and change the 'If...' line to vbYes.

Nigel
 
Nigel,
Works exactly like I want it to.... THANKS. One thing though. The append query has its own warning when you click on it normally. However, after I choose OK, this warning shows up twice before activating the query... do you see what might be causing that in the code below? Thanks for your help! :

Private Sub Command25_Click()
On Error GoTo Err_Command25_Click

Dim intPress As Integer

intPress = MsgBox("MAKE SURE EXCEL FILE DATA HAS BEEN REFRESHED", vbWarning + vbOKCancel, "WARNING")

If intPress = vbOK Then
DoCmd.OpenQuery "Add New Vendor Billing Records"


Dim stDocName As String

stDocName = "Add new Vendor Billing Records"
DoCmd.OpenQuery stDocName, acNormal, acEdit

Exit_Command25_Click:
Exit Sub

Err_Command25_Click:
MsgBox Err.Description
Resume Exit_Command25_Click
End If
End Sub


Nino
 
Forget it Nigel... I got it! For those interested, this is what it looks like.

Private Sub Command25_Click()
On Error GoTo Err_Command25_Click

Dim intPress As Integer

intPress = MsgBox("MAKE SURE EXCEL FILE DATA HAS BEEN REFRESHED", vbWarning + vbOKCancel, "WARNING")

If intPress = vbOK Then
DoCmd.OpenQuery "Add New Vendor Billing Records"


Dim stDocName As String

stDocName = "Add new Vendor Billing Records"
DoCmd.OpenQuery stDocName, acNormal, acEdit

Exit_Command25_Click:
Exit Sub

Err_Command25_Click:
MsgBox Err.Description
Resume Exit_Command25_Click
End If
End Sub

Nino
 
Nino
The reason for two messages is that your code was effectively running the query twice. I have tidied it up a bit as below. Also added a couple of lines which get rid of the standard message.

Dim intPress As Integer
Dim stDocName As String

DoCmd.SetWarnings False

intPress = MsgBox("MAKE SURE EXCEL FILE DATA HAS BEEN REFRESHED", vbWarning + vbOKCancel, "WARNING")

If intPress = vbOK Then
stDocName = "Add new Vendor Billing Records"
DoCmd.OpenQuery stDocName, acNormal, acEdit

End If

DoCmd.SetWarnings True

Exit_Command25_Click:
Exit Sub

Err_Command25_Click:
MsgBox Err.Description
Resume Exit_Command25_Click
End Sub



Should work for you- give me a shout if not.

Nigel
 
Thanks Nigel... I used yours instead. Looks like I copy and pasted my code incorrectly above.

Nino
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top