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 » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Preview doesn't open current record



 
 
Thread Tools Display Modes
  #1  
Old January 30th, 2008, 07:55 PM posted to microsoft.public.access
CW
external usenet poster
 
Posts: 701
Default Preview doesn't open current record

I have the basic details of our invoices (which are reports) displayed on a
continuous form i.e. date, number, customer, amount. At the end of each row I
have a button so that we can open the form on which the invoice was created,
to modify it. That works fine, it opens the selected invoice.
I also have a button that should open a preview of the selected invoice
(rpt). However, I can't get this to fire the correct record - it insists on
opening the last (most recently created) invoice, no matter on which line the
record selector may be.
This is the code I am using on the Click event of that button:

Private Sub cmdPreviewInvoice_Click()
On Error GoTo Err_cmdPreviewInvoice_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "rptInvoicePrint"

stLinkCriteria = "[InvNo]=" & Me![InvNo]
DoCmd.OpenReport stDocName, , , stLinkCriteria, acPreview

Exit_cmdPreviewInvoice_Click:
Exit Sub

Err_cmdPreviewInvoice_Click:
MsgBox Err.Description
Resume Exit_cmdPreviewInvoice_Click

End Sub


Where am I going wrong??
Thanks a lot
CW
  #2  
Old January 30th, 2008, 10:51 PM posted to microsoft.public.access
fredg
external usenet poster
 
Posts: 4,386
Default Preview doesn't open current record

On Wed, 30 Jan 2008 11:55:01 -0800, CW wrote:

I have the basic details of our invoices (which are reports) displayed on a
continuous form i.e. date, number, customer, amount. At the end of each row I
have a button so that we can open the form on which the invoice was created,
to modify it. That works fine, it opens the selected invoice.
I also have a button that should open a preview of the selected invoice
(rpt). However, I can't get this to fire the correct record - it insists on
opening the last (most recently created) invoice, no matter on which line the
record selector may be.
This is the code I am using on the Click event of that button:

Private Sub cmdPreviewInvoice_Click()
On Error GoTo Err_cmdPreviewInvoice_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "rptInvoicePrint"

stLinkCriteria = "[InvNo]=" & Me![InvNo]
DoCmd.OpenReport stDocName, , , stLinkCriteria, acPreview

Exit_cmdPreviewInvoice_Click:
Exit Sub

Err_cmdPreviewInvoice_Click:
MsgBox Err.Description
Resume Exit_cmdPreviewInvoice_Click

End Sub

Where am I going wrong??
Thanks a lot
CW


I see 2 errors.
1) Access doesn't save new data unless you navigate to another record,
close the form, or explicitly tell it to save the data.

Add one line of code to your existing code (Marked with '*** below):

Private Sub cmdPreviewInvoice_Click()
On Error GoTo Err_cmdPreviewInvoice_Click

DoCmd.RunCommand acCmdSaveRecord '***

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "rptInvoicePrint"

stLinkCriteria = "[InvNo]=" & Me![InvNo]

etc..... See #2 below

2) Also Note that your OpenReport syntax is not correct.

You have...
DoCmd.OpenReport stDocName, , , stLinkCriteria, acPreview

It should be....
DoCmd.OpenReport stDocName, acViewPreview, , stLinkCriteria

etc........

--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
  #3  
Old January 31st, 2008, 12:01 AM posted to microsoft.public.access
CW
external usenet poster
 
Posts: 701
Default Preview doesn't open current record

I'm always happy to get an answer from you Fred, cos I know it's always going
to work - thanks a lot
CW

"fredg" wrote:

On Wed, 30 Jan 2008 11:55:01 -0800, CW wrote:

I have the basic details of our invoices (which are reports) displayed on a
continuous form i.e. date, number, customer, amount. At the end of each row I
have a button so that we can open the form on which the invoice was created,
to modify it. That works fine, it opens the selected invoice.
I also have a button that should open a preview of the selected invoice
(rpt). However, I can't get this to fire the correct record - it insists on
opening the last (most recently created) invoice, no matter on which line the
record selector may be.
This is the code I am using on the Click event of that button:

Private Sub cmdPreviewInvoice_Click()
On Error GoTo Err_cmdPreviewInvoice_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "rptInvoicePrint"

stLinkCriteria = "[InvNo]=" & Me![InvNo]
DoCmd.OpenReport stDocName, , , stLinkCriteria, acPreview

Exit_cmdPreviewInvoice_Click:
Exit Sub

Err_cmdPreviewInvoice_Click:
MsgBox Err.Description
Resume Exit_cmdPreviewInvoice_Click

End Sub

Where am I going wrong??
Thanks a lot
CW


I see 2 errors.
1) Access doesn't save new data unless you navigate to another record,
close the form, or explicitly tell it to save the data.

Add one line of code to your existing code (Marked with '*** below):

Private Sub cmdPreviewInvoice_Click()
On Error GoTo Err_cmdPreviewInvoice_Click

DoCmd.RunCommand acCmdSaveRecord '***

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "rptInvoicePrint"

stLinkCriteria = "[InvNo]=" & Me![InvNo]

etc..... See #2 below

2) Also Note that your OpenReport syntax is not correct.

You have...
DoCmd.OpenReport stDocName, , , stLinkCriteria, acPreview

It should be....
DoCmd.OpenReport stDocName, acViewPreview, , stLinkCriteria

etc........

--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail

 




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 12:02 AM.


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