Hi all, hope you can help with this as I am a bit of a newbie when it comes to Access and VBA...
I am developing a database system at work that is used to record audits of work quality, and we want to be able to e-mail an Access report to workers where quality issues have been identified - nothing special, just a single record report.
The auditor selects an audit record from a listbox on the main form - the first column of which is the unique ID of the audit. Below the list box I have put three command buttons which allow the report to be viewed, printed or e-mailed, the first two of which are working very nicely thanks to the 'OpenArgs' attribute in DoCmd.OpenObject. The 'proforma' report is also called from two other forms which are used for creating the audit records in the back-end tables, and when a 'fail' record is added a module is called which saves a Snapshot Format copy of the report to a network drive. This too works fine.
I have a problem however when trying to generate the report when using DoCmd.SendObject - no matter what method I use to input it, the report simply will not pick up the unique audit record ID to complete the SQL command which populates the fields in the report. I have written a new function in a module for generating the e-mail, and the e-mail itself is generating fine, however the attachment generated by SendObject is just the report template.
On the main form the code behind the command button which attempts to send the e-mail is very simple:
The argument for getting the record ID into this function has been coded as follows:
The first lines of the Reports 'On Activate' routine deal with picking up the audit record ID from the various inputs mentioned before. I am going from memory on this a bit, but is essentially as follows:
The last part of the group of IF's is the bit I'm trying to get to work when sending the report via e-mail. I have tried populating this from the listbox on the main form, a hidden text field which contains the same value as the selected record in the listbox in both a new form as well as the original main form, all to no avail thus far which is very frustrating to say the least! :banghead:
We are running Access 2003 (SP3) on Windows XP currently. I will try and get online here tomorrow at work and post up all the relevant code tomorrow but in the meantime maybe what I have posted here will be sufficient for one of you boffins to be able to spot where I am running into trouble
I am developing a database system at work that is used to record audits of work quality, and we want to be able to e-mail an Access report to workers where quality issues have been identified - nothing special, just a single record report.
The auditor selects an audit record from a listbox on the main form - the first column of which is the unique ID of the audit. Below the list box I have put three command buttons which allow the report to be viewed, printed or e-mailed, the first two of which are working very nicely thanks to the 'OpenArgs' attribute in DoCmd.OpenObject. The 'proforma' report is also called from two other forms which are used for creating the audit records in the back-end tables, and when a 'fail' record is added a module is called which saves a Snapshot Format copy of the report to a network drive. This too works fine.
I have a problem however when trying to generate the report when using DoCmd.SendObject - no matter what method I use to input it, the report simply will not pick up the unique audit record ID to complete the SQL command which populates the fields in the report. I have written a new function in a module for generating the e-mail, and the e-mail itself is generating fine, however the attachment generated by SendObject is just the report template.
On the main form the code behind the command button which attempts to send the e-mail is very simple:
Code:
run sendproforma(Me.LstHistory.Column(0))
The argument for getting the record ID into this function has been coded as follows:
Code:
Public Function sendproforma(auditID As String)
The first lines of the Reports 'On Activate' routine deal with picking up the audit record ID from the various inputs mentioned before. I am going from memory on this a bit, but is essentially as follows:
Code:
Dim strvariable, SQL As String
If forms!frmresults1.IsLoaded Then
strvariable = forms!frmresults1.UniqueID
ElseIf forms!frmresults1view.IsLoaded Then
strvariable = forms!frmresults1view.NewUniqueID
ElseIf Not IsNull(Me.OpenArgs) Then
strvariable = Me.OpenArgs
Else
strvariable = auditID
End If
SQL = "SELECT * FROM qryauditresults WHERE uniqueref = '" & strvariable & "'"
The last part of the group of IF's is the bit I'm trying to get to work when sending the report via e-mail. I have tried populating this from the listbox on the main form, a hidden text field which contains the same value as the selected record in the listbox in both a new form as well as the original main form, all to no avail thus far which is very frustrating to say the least! :banghead:
We are running Access 2003 (SP3) on Windows XP currently. I will try and get online here tomorrow at work and post up all the relevant code tomorrow but in the meantime maybe what I have posted here will be sufficient for one of you boffins to be able to spot where I am running into trouble
Last edited: