selecting fields (1 Viewer)

Robster

Registered User.
Local time
Today, 12:20
Joined
Mar 13, 2014
Messages
60
I have an on click event to mail a report which works.
I want to change the text to include data from a table.

I changed the code to include the field 'office' from the table 'Checks' but get an error saying 'Object required'.

Code is :
Private Sub cmd_mailreport_Click()

Dim office As Object

Set office = Checks.office

DoCmd.SendObject acReport, "checks", "PDFFormat(*.pdf)", _
"info@company.com", "", "", office & " Daily Check - " & Date, "Attached is the report for the office", _
True, ""


End Sub


Many thanks for your help.
 

Christos99

Registered User.
Local time
Today, 12:20
Joined
Dec 19, 2013
Messages
24
Access isn't going to understand what you are doing here. You want Office to be a string variable if you are including it as text in your sendobject command.

If you know the office in advance of calling cmd_mailreport you could pass as a parameter like cmd_mailreport_Click(strOffice as string).

Otherwise you will have to read the Office from the table like:

dim db as database, rst as recordset, strOffice as string
set db = currentdb
set rst = db.openrecordset("Checks",dbopentable, dbreadonly)

If there is only one record in Checks then :
strOffice = rst!Office
Otherwise you will have to lookup the record required based on criteria only you know, maybe an ID passed to the function ?

Remember to tidyup
rst.close
set rst = nothing
set db = nothing
 

Users who are viewing this thread

Top Bottom