A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Cannot Get the Yes Button to open Report



 
 
Thread Tools Display Modes
  #1  
Old January 22nd, 2009, 06:45 AM posted to microsoft.public.access.forms
jesseu via AccessMonster.com
external usenet poster
 
Posts: 3
Default Cannot Get the Yes Button to open Report

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

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/200901/1

  #2  
Old January 22nd, 2009, 07:32 AM posted to microsoft.public.access.forms
Allen Browne
external usenet poster
 
Posts: 11,706
Default Cannot Get the Yes Button to open Report

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.)

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"jesseu via AccessMonster.com" u39476@uwe wrote in message
news:908d72cb82bd4@uwe...
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


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 06:13 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.