Results 1 to 3 of 3
  1. #1
    CaveCanem is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2012
    Posts
    9

    Generating a report based upon a condition

    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.

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    If you click on a button, you will not have focus on a record within a Continuous or Datasheet view form. Perhaps a double click event in the subform will help the user communicate which client is relevant.

    Consider Docmd.Output to and a format argument of acFormatPDF to send a report as an attachment.

  3. #3
    CaveCanem is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2012
    Posts
    9
    Quote Originally Posted by ItsMe View Post
    If you click on a button, you will not have focus on a record within a Continuous or Datasheet view form.
    Of course. How obvious. Thanks for the help.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Hide field in sub-report based on condition
    By vinsavant in forum Reports
    Replies: 4
    Last Post: 12-16-2012, 10:18 AM
  2. Replies: 5
    Last Post: 05-05-2012, 10:11 AM
  3. Replies: 4
    Last Post: 07-27-2011, 12:42 PM
  4. Replies: 3
    Last Post: 11-19-2010, 01:48 PM
  5. Highlighting Report Data Based on a Condition
    By KramerJ in forum Reports
    Replies: 1
    Last Post: 05-29-2009, 10:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums