Cannot Get the Yes Button to open Report

  • Thread starter jesseu via AccessMonster.com
  • Start date
J

jesseu via AccessMonster.com

New to code, I can get the message box to open, but cannot get the report to
open when I click the Yes Buttom. Can anyone see what I have done wrong with
the code.
Thank You
Jesse

Private Sub Form_AfterInsert()
Dim Msg, Style, Title, MyString
Msg = "Would You Like To Print Label" ' Define message.
Style = 4 + 16 + 0 ' Define buttons.
Title = "ESS Label" ' Define title.
Dim stDocName As String

If Me![Text6] = 3 - 1 Then
Response = MsgBox(Msg, Style, Title)
ElseIf Response = vbYes Then ' User chose Yes.
MyString = "Yes"
DoCmd.OpenReport "person" ' Perform some action.
Else ' User chose No.
MyString = "No"
' Perform some action.
End If

End Sub
 
A

Allen Browne

Temporarily add another MsgBox to indicate if the report opened or not. This
will help you identify whether the problem is with your code or with
something else (such as the report's query is incorrect, or its Open or
NoData event is cancelled, or the printer is not working, or ...)

Private Sub Form_AfterInsert()
Dim strMsg As String
strMsg = "Would You Like To Print Label"
If MsgBox(strMsg, vbYesNo+vbQuestion, "ESS Label") = vbYes Then
DoCmd.Report "person"
MsgBox "Report opened"
End If
End Sub

Other suggestions:
- Make sure you have Option Explicit at the top of this (and all other)
modules.

- Make sure your code compiles (Compile on Debug menu in code window.)

- Don't declare all variables on one line.
Instead declare each one with its type (e.g. "As String" above.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top