Button to automatically mail a flitered report

D

Daisyd

Hello

I'm trying to create a button on a form that when clicked automatically
mails a report. However, the tricky part is that I want that report to only
contain the data from the current record.

I am an Access amateur but have fudged together the following code where
"Bookingref" is the field that identifies the current and "Invoice
Instruction" is the report I want to mail.

Something's not quite working and I'm too much of an idiot to know what it is.

Private Sub Mail_Report_Click()
On Error GoTo Err_Mail_Report_Click

Dim stDocName As String
Dim MyWhereCondition As String

MyWhereCondition = "Bookingref= " & Me.Bookingref

stDocName = "Invoice Instruction"
DoCmd.SendObject acReport, stDocName, , MyWhereCondition

Exit_Mail_Report_Click:
Exit Sub

Err_Mail_Report_Click:
MsgBox Err.Description
Resume Exit_Mail_Report_Click

End Sub
 
D

Douglas J. Steele

Unfortunately, "something's not quite working" really doesn't give us much
to go by.

Are you getting an error message? If so, what's the error? If you're not
getting an error, what are you getting, and what do you want instead?
 
D

Daisyd

Hi Douglas

Thanks for responding. I've no found my solution. Just a matter of a
missing comma. for anyone interested the code now reads:

Private Sub Mail_Report_Click()
On Error GoTo Err_Mail_Report_Click

Dim MyWhereCondition As String
MyWhereCondition = "Bookingref= " & Me.Bookingref
DoCmd.OpenReport "Invoice Instruction", acPreview, , MyWhereCondition
DoCmd.SendObject acSendReport, "Invoice Instruction"


Exit_Mail_Report_Click:
Exit Sub

Err_Mail_Report_Click:
MsgBox Err.Description
Resume Exit_Mail_Report_Click

End Sub
 

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

Similar Threads


Top