Results 1 to 8 of 8
  1. #1
    New Lounger
    Join Date
    Apr 2005
    Location
    Kansas City, Missouri, USA
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Access Report VBA error (Access 2000 Pro)

    Getting this error when execute the cmdEmail button.

    An expression you entered is the wrong data types for one of the arguements.

    Here is the code:

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "rptBy_Client"
    stLinkCriteria = "[Client_Number]=" & Me![Client_Number]
    DoCmd.SendObject acReport, stDocName, , Me.Client_Email, , , Client_Activity_Report, , True, stLinkCriteria

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Access Report VBA error (Access 2000 Pro)

    You can't pass a criteria string to DoCmd.SendObject. As with your OpenReport question in <post#=477891>post 477891</post#>, it helps to look up the syntax of a method. Click somewhere in the word OpenReport or SendObject and press F1 to get online help.

    If you want to e-mail a filtered report, you will have to place the criteria in its record source, or apply the filter in the On Open event of the report.

  3. #3
    New Lounger
    Join Date
    Apr 2005
    Location
    Kansas City, Missouri, USA
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Access Report VBA error (Access 2000 Pro)

    Okay, I put it on an open event for the report but now I am unable to specify the field from the form that was filling in the TO:

    I tried this statement: [FORMS]![frmClient_Companies]![Client_Email]
    but it says access can't find the form.

    Stacy

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Access Report VBA error (Access 2000 Pro)

    It will only work if the form is open.

  5. #5
    New Lounger
    Join Date
    Apr 2005
    Location
    Kansas City, Missouri, USA
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Access Report VBA error (Access 2000 Pro)

    Thanks Hans,
    I put a filter on the report in its properties. That works.
    I put a Macro for the sendobject on the activate properties. That works.
    However, I still cannot get it to let me specify the field from either the FORM or REPORT to populate the TO:

    When I did it with the FORMS!FORM my form was still open.
    Stacy

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Access Report VBA error (Access 2000 Pro)

    What exactly are you using now to send the report? Please provide complete and detailed information.

  7. #7
    New Lounger
    Join Date
    Apr 2005
    Location
    Kansas City, Missouri, USA
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Access Report VBA error (Access 2000 Pro)

    Okay here goes... <img src=/S/smile.gif border=0 alt=smile width=15 height=15>
    I have a form for Client Companies. I made a command button to pull up a report, filtered by the individual company. Once that report is up I want to send it through email. Having the TO: field in OUTLOOK populate from the Client_Email field on the form.

    Currently, this is what I have coded under the cmdEmail Button on the frmClientCompanies:
    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "rptBy_Client"
    stLinkCriteria = "[Client_Number]=" & Me![Client_Number]
    DoCmd.OpenReport stDocName, acViewPreview, , stLinkCriteria

    Then under the Activate Property of the rptBy_Client, I have a Macro_Email:
    SendObject
    Object type: Report
    Object name: rptBy_Client
    Output format: Snapshot
    Subject: Client Activity Report
    Edit Message: Yes

    I hope this was detailed enough.
    Stacy

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Access Report VBA error (Access 2000 Pro)

    When you execute SendObject, the report will be opened anew, withoyt the filter specified in the OpenReport method. Try the following:

    1. The report.
    - Open the report in design view.
    - Activate the Event tab of the Properties window.
    - Clear the On Activate property.
    - Click in the On Open property.
    - Select [Event Procedure] from the dropdown list.
    - Click the ... to the right of the dropdown arrow.
    - Make the code look like this:

    Private Sub Report_Open(Cancel As Integer)
    Me.Filter = "[Client_Number]=" & Forms!frmClientCompanies![Client_Number]
    Me.FilterOn = True
    End Sub

    - Close and save the report.

    2. The button on the form.
    - Make the code for the On Click event of the command button on the form look like this:

    Private Sub cndEmail_Click()
    On Error GoTo ErrHandler
    DoCmd.SendObject acSendReport, "rptBy_Client",acFormatSNP, Me.[Client_Email], , , "Client Activity Report"
    Exit Sub

    ErrHandler:
    If Err = 2501 Then
    ' Report or e-mail canceled. Ignore
    Else
    MsgBox Err.Description, vbExclamation
    End If
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •