Inserting a value into a report triggered by a select query

R

Robert Robinson

I have created a form which generates an invoice number. I have also created
an invoice (report) which is based on the values in this form. The report is
based on a query which prompts for invoice number. Thus when the user prints
the invoice based on the data in the current screen, they are prompted to
enter the invoice number (a duplication of effort). What I would like to do
is code the form to pass the current invoice number to the query which powers
the report (invoice). I have tried to code this in the On Click command button

Private Sub Preview_Invoice_Click()
On Error GoTo Err_Preview_Invoice_Click
If Not IsNull(Me![InvoiceID]) Then
Invoice![InvoiceID] = Me![InvoiceID]
DoCmd.OpenReport "Invoice", acPreview
Exit_Preview_Invoice_Click:
Exit Sub
Err_Preview_Invoice_Click:
MsgBox Err.Description
Resume Exit_Preview_Invoice_Click
End Sub

However, I can not get the invoice date to pass into the invoice report. Am
I off with the command passing the invoice number to the invoice report
(should that code come after the DoCmd code?) Is it because I am passing the
invoice number to the report, rather than the query? Please advise.
 
D

David Lloyd

Robert:

You can directly reference the InvoiceID control in your form in the query
behind the report. This is generally referred to as the "Query By Form"
technique. The following KB article gives more information.

http://support.microsoft.com/default.aspx?scid=kb;en-us;304428

--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.


message I have created a form which generates an invoice number. I have also created
an invoice (report) which is based on the values in this form. The report is
based on a query which prompts for invoice number. Thus when the user prints
the invoice based on the data in the current screen, they are prompted to
enter the invoice number (a duplication of effort). What I would like to do
is code the form to pass the current invoice number to the query which
powers
the report (invoice). I have tried to code this in the On Click command
button

Private Sub Preview_Invoice_Click()
On Error GoTo Err_Preview_Invoice_Click
If Not IsNull(Me![InvoiceID]) Then
Invoice![InvoiceID] = Me![InvoiceID]
DoCmd.OpenReport "Invoice", acPreview
Exit_Preview_Invoice_Click:
Exit Sub
Err_Preview_Invoice_Click:
MsgBox Err.Description
Resume Exit_Preview_Invoice_Click
End Sub

However, I can not get the invoice date to pass into the invoice report. Am
I off with the command passing the invoice number to the invoice report
(should that code come after the DoCmd code?) Is it because I am passing the
invoice number to the report, rather than the query? Please advise.
 

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