Passing info to a Report

P

Pat

Hey all, with a new version of Office once again comes a question from me
about adjusting my coding. I'm still very much new to learning the Visual
Basic language so bear with me if you find the answer to be blantantly
obvious. :)

Here is my code as is:

Private Sub cmdPrintInvoice_Click()

On Error GoTo Err_Handler
DoCmd.RunCommand acCmdSaveRecord

Dim strReportName As String
Dim strCriteria As String

strReportName = "rptInternationalInvoice"
strCriteria = "[InvoiceID]=" & Me![InvoiceID]
DoCmd.OpenReport strReportName, acViewPreview, , strCriteria

Exit_This_Sub:
Exit Sub
Err_Handler:
If Err = 2501 Then
Else
MsgBox "Error# " & Err.Number & "" & Err.Description
End If
Resume Exit_This_Sub
End Sub

What this does is I fill out information in a form, in this case for
creating a commercial invoice, and then I click a button which calls this
procedure above to send the info to a report that I can then print out. The
form has a subform which contains the product list while the main form has
all the other information. Now, this worked fine with Office 03. But of
course Office 07 comes along and now I get nothing.

Here's a bit of weirdness to throw at you. If I select an invoice that's
already in the database and change the product contents and address,
basically everything, then I click the Print button and it works just fine.
If I create a new record on the other hand, it allows me to fill out all the
information just fine but when I click on that print button I get a report
without any data to it AND if I go back to the form again it doesn't
recognize that any data was ever entered much less a new record created. So
basically I'm stuck now with 19 different invoices and it won't save anymore.
Completely weird! But again, knowing this crowd one of you will probably
immediately see the problem in my coding. And how I came up with this code
was originally off a forum just for MS Access years ago and this current form
of the code came from one of you here. Thank you again whoever you are!
Worked great while it did.

So any thoughts at all on this are greatly welcomed. And along those lines,
if one of you cares to explain the procedures used in the coding including
the different parameters and such I'd certainly enjoy the bit of education.
Thanks all!
 
N

NetworkTrade

If all works well in Access2003 and it is not working in Access2007; then I
would recommend in 07 that you look at the queries that are the record
sources for the Report and its SubReport.

1. Be sure that the key field is in the queries
2. Be sure that the key field is in the actual report/subreport - even if
not visible.

I found this to be the fix of several similar issues involving forms/reports
that had subforms/reports. Where it worked fine in 03 it did not work right
in 07; it is as if 07 is more strict.....I went thru and made sure that the
key field was in all queries and in all forms/reports - even when the field
was not needed by the human and often made invisible - - - but this
worked...try it. It was advice from one of the MVPs to me and worked....
--
NTC


Pat said:
Hey all, with a new version of Office once again comes a question from me
about adjusting my coding. I'm still very much new to learning the Visual
Basic language so bear with me if you find the answer to be blantantly
obvious. :)

Here is my code as is:

Private Sub cmdPrintInvoice_Click()

On Error GoTo Err_Handler
DoCmd.RunCommand acCmdSaveRecord

Dim strReportName As String
Dim strCriteria As String

strReportName = "rptInternationalInvoice"
strCriteria = "[InvoiceID]=" & Me![InvoiceID]
DoCmd.OpenReport strReportName, acViewPreview, , strCriteria

Exit_This_Sub:
Exit Sub
Err_Handler:
If Err = 2501 Then
Else
MsgBox "Error# " & Err.Number & "" & Err.Description
End If
Resume Exit_This_Sub
End Sub

What this does is I fill out information in a form, in this case for
creating a commercial invoice, and then I click a button which calls this
procedure above to send the info to a report that I can then print out. The
form has a subform which contains the product list while the main form has
all the other information. Now, this worked fine with Office 03. But of
course Office 07 comes along and now I get nothing.

Here's a bit of weirdness to throw at you. If I select an invoice that's
already in the database and change the product contents and address,
basically everything, then I click the Print button and it works just fine.
If I create a new record on the other hand, it allows me to fill out all the
information just fine but when I click on that print button I get a report
without any data to it AND if I go back to the form again it doesn't
recognize that any data was ever entered much less a new record created. So
basically I'm stuck now with 19 different invoices and it won't save anymore.
Completely weird! But again, knowing this crowd one of you will probably
immediately see the problem in my coding. And how I came up with this code
was originally off a forum just for MS Access years ago and this current form
of the code came from one of you here. Thank you again whoever you are!
Worked great while it did.

So any thoughts at all on this are greatly welcomed. And along those lines,
if one of you cares to explain the procedures used in the coding including
the different parameters and such I'd certainly enjoy the bit of education.
Thanks all!
 
A

Albert D. Kallal

Actually I can't see how worked correctly in access 2003, because you're
launching a report that works to the current record, but the current record
has not been written to disk?

you need to force the current record to be read into the distraught, because
the report does not read from your form, but reads from the actual data
file.

simply add the following code

Dim strReportName As String
Dim strCriteria As String

strReportName = "rptInternationalInvoice"
strCriteria = "[InvoiceID]=" & Me![InvoiceID]

if me.Dirty = true then
me.dirty = false <--- force a disk write
end if

DoCmd.OpenReport strReportName, acViewPreview, , strCriteria
 
P

Pat

Thanks to both of you for your replies. I'm looking at all this, updated the
code and still nothing. I tried looking at the queries that I have. One for
the main form and one for the details which would be the products. For
whatever reason, it does actually appear that the information is being stored
into the tables as it should still. However, for whatever reason the query
for the main form, which is also the query the report uses, is NOT pulling up
the information. It pulls the info from the 19 records that were already
there. But it won't pull any of the newer ones that I've attempted to do.
Thoughts? I'm a bit puzzled by this. Especially when I haven't changed
anything on the computer or in this database....aside from the update from
Office 2003 to Office 2007.
 

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