I have a database with two main tables. One for client demographics, the second for client contacts. They are related on a unique client ID.
I enter the demographic data via a form. That form has a subform that displays all records from the Client Contact Table related to the active Client Demographic record. The subform also allows for the entry of additional client contact records.
I have created a button for the subform that, when clicked, prompts the user to enter the ID of a record from the "Client Contact" table, generates a report on the selected record, and attaches it to an email. I have been trying to modify the VB code a bit and am having trouble figuring it all out. Any help would be appreciated. What I ultimately want to do is this:
1. Click the button.
2. Get the ID of the record in the contact table that currently has focus (ie, so that the user doesn't have to enter it manually).
3. Get the value of the "Staff ID" field in the selected record.
4. Generate one of several different reports for the selected record depending on the value of the "Staff ID".
5. Attach the report to an email.
Here is the code as I currently have it:
Code:
Private Sub ChargReportButton_Click()
On Error GoTo Err_ChargReportButton_Click
Dim stDocName As String
stDocName = "Charges_Report"
DoCmd.OpenReport stDocName, acViewReport, , "FieldName = " & Me.ID
Exit_ChargReportButton_Click:
Exit Sub
Err_ChargReportButton_Click:
MsgBox Err.Description
Resume Exit_ChargReportButton_Click
End Sub
Private Sub ChargeReport_Click()
On Error GoTo Err_ChargeReport_Click
Dim stDocName As String
stDocName = "Charges_Report"
DoCmd.SendObject acReport, stDocName, acFormatPDF, , , , "Charge Sheet"
Exit_ChargeReport_Click:
Exit Sub
Err_ChargeReport_Click:
MsgBox Err.Description
Resume Exit_ChargeReport_Click
End Sub
Thanks again for any help.