Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 38
  1. #16
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929

    Did you try the revised code?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  2. #17
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    839
    I am using this: DoCmd.OutputTo 3, "By Field Report", acFormatPDF, "C:\users\Username\Documents\TempA\By Field - " & Me.Controls(Me.[Field Name]) & " - " & Format(Date, "dd mmm yyyy") & ".pdf", , 0

    When I do this for the Me.Controls(Me.[Field Name]) is get an error saying the dB cannot find the field "Instrumentation" or whatever I select from the Select Field form.

  3. #18
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I don't see a field "Instrumentation" in the query in post 13. The code expects these fields to be in the form's RecordSource.

    Maybe I don't understand what you are really trying to do.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #19
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    839
    "Instrumentation" is one of the Field Names.

    I have a form with a combo box named "My Field" the record source is from a table named Field. This sets up the [By Field] query with Like "[Forms]![Select Field].[My Field] & "*" " in the criteria of the [Field Name] column. Then the [By Field Report] opens and displays the selected field.

    What I am having issues with -

    If I put in the Me.Controls(Me.[Field Name]) it comes up with the error stating that "Microsoft Access cannot find the field (whatever field is selected) referred to in your expression".
    If I put in the Me.Controls(Me.[My Field Name]) it comes up with the error stating "Microsoft Access cannot find the field '|1' referred to in your expression".

    DoCmd.OutputTo 3, "By Field Report", acFormatPDF, "C:\users\username\Documents\TempA\By Field - " & Me.Controls(Me.[Field_Name]) & " - " & Format(Date, "dd mmm yyyy") & ".pdf", , 0

  5. #20
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Since the code is referencing Controls collection, needs to be a control named "Instrumentation" bound to field "Instrumentation". Since Instrumentation is not in the posted query, how do you expect to pull values from that field?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #21
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    839
    DoCmd.OutputTo 3, "By Field Report", acFormatPDF, "C:\users\wayne.p.thompson\Documents\TempA\By Field - " & Me.[Field Name] & " - " & Format(Date, "dd mmm yyyy") & ".pdf", , 0

    Fixed - changed Me.Controls(Me.[Field Name]) to Me.[Field Name] Works fine now.

  7. #22
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    839
    Next step is to pick up this in an email from the stored location, then delete it.

  8. #23
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    839
    This is what I have developed so far and I added it in the EMAIL VBA vice the Sendobject.

    Attachments.Add "C:\users\username\Documents\TempA\Like " * ""

    With this I get a mismatch error 13.

    If I use Like [*]* or ? o get and Expected End of Statement Error.

  9. #24
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Certainly would not use LIKE operator.

    Attachments.Add "C:\users\username\Documents\TempA\*.*"

    However, I have no idea if wildcard will work. Might have to add each attachment individually.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  10. #25
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    839
    wildcard doesn't work *.* still get an error 424 Object Required.

    Tried this:
    Code:
    Attachments.Add "C:\users\username\Documents\TempA\By Field - " & Me.[Field Name] & " - " & Format(Date, "dd mmm yyyy") & ".pdf"
    Comes out the same. How would I specify the object?

  11. #26
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Sorry, just noticed you said "SendObject", cannot attach files with SendObject method.

    Would have to open and manipulate an Outlook mail object. Review: https://www.accessforums.net/access/...ect-17713.html
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  12. #27
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    839
    Dang, making it even harder. LOL, Thanks June, I'll see what i can do. I'll definitally give a hollar.

  13. #28
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    839
    I tried the following:
    Code:
    Private Sub sbSendMessage_Click()
     Dim objOutlook As Outlook.Application
     Dim objOutlookMsg As Outlook.MailItem
     Dim objOutlookAttach As Outlook.Attachment
    Dim strSubject, strBody, strAddresses, strFile As String
     On Error GoTo ErrorMsgs
    Set objOutlook = CreateObject("Outlook.Application")
    Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
    With objOutlookMsg
     If Not IsNull(MyField) Then
    
    'Signature Block
        strBody = strBody & vbCrLf & vbCrLf & vbCrLf
        strBody = strBody & "V/R" & vbCrLf
        strBody = strBody & "Name" & vbCrLf & vbCrLf
        strBody = strBody & "Command"& vbCrLf
        strBody = strBody & "Division" & vbCrLf
        strBody = strBody & "Address 1" & vbCrLf
        strBody = strBody & "Address 2" & vbCrLf
        strBody = strBody & "Phone Number" & vbCrLf
        strBody = strBody & "Email address" & vbCrLf
        strSubject = "By Field Report - " & ![Field Name] & " - " & Format(Now, "dd mmm yyyy")
    ' Make file       
    DoCmd.OutputTo 3, "By Field Report", acFormatPDF, "C:\users\wayne.p.thompson\Documents\TempA\By Field - " & Me.[Field Name] & " - " & Format(Date, "dd mmm yyyy") & ".pdf", , 0
    'Close form
    DoCmd.Close acForm, "By Field"
    
     '.Subject = "This is an Automation test with Microsoft Outlook"
     '.Body = "Last test." & vbCrLf & vbCrLf
    
     If Not IsMissing(AttachmentPath) Then
     Set objOutlookAttach = .Attachments.Add("C:\users\wayne.p.thompson\Documents\TempA\By Field - " & Me.[Field Name] & " - " & Format(Date, "dd mmm yyyy") & ".pdf", , 0)
      End If
      End If
     End With
     Set objOutlookMsg = Nothing
     Set objOutlook = Nothing
     Set objOutlookRecip = Nothing
     Set objOutlookAttach = Nothing
     Exit Sub
    ErrorMsgs:
     If Err.Number = "287" Then
     MsgBox "You clicked No to the Outlook security warning. " & _
     "Rerun the procedure and click Yes to access e-mail " & _
     "addresses to send your message. "
     Else
     MsgBox Err.Number & " " & Err.Description
    End If
    End Sub
    I get a "438 Object doesn't support this property or method." error

  14. #29
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    On what line??

    In my code, I don't declare and set an attachment object.

    With objOutlookMsg
    ...
    .Attachments.add ("file path and name here")
    .DeleteAfterSubmit = True
    .Send
    End With
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  15. #30
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    839
    June,
    Corrected with your script:
    Code:
    Private Sub sbSendMessage_Click()
     On Error GoTo ErrorMsgs
     Dim objOutlook As Outlook.Application
     Dim objOutlookMsg As Outlook.MailItem
     Dim objOutlookAttach As Outlook.Attachment
     Dim strSubject, strBody, strAddresses, strFile As String
    Set objOutlook = CreateObject("Outlook.Application")
    Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
    With objOutlookMsg
     If Not IsNull(MyField) Then
        strBody = strBody & vbCrLf & vbCrLf & vbCrLf
        strBody = strBody & "V/R" & vbCrLf
        strBody = strBody & "Name" & vbCrLf & vbCrLf
        strBody = strBody & "Command" & vbCrLf
        strBody = strBody & "Division" & vbCrLf
        strBody = strBody & "Addy" & vbCrLf
        strBody = strBody & "Zip" & vbCrLf
        strBody = strBody & 'Phone" & vbCrLf
        strBody = strBody & "email" & vbCrLf
        strSubject = "By Field Report - " & ![Field Name] & " - " & Format(Now, "dd mmm yyyy")
         DoCmd.OutputTo 3, "By Field Report", acFormatPDF, "C:\users\wayne.p.thompson\Documents\TempA\By Field - " & Me.[Field Name] & " - " & Format(Date, "dd mmm yyyy") & ".pdf", , 0
         DoCmd.Close acForm, "By Field"
        Attachments.Add ("C:\users\wayne.p.thompson\Documents\TempA\By Field - " & Me.[Field Name] & " - " & Format(Date, "dd mmm yyyy") & ".pdf")
       .DeleteAfterSubmit = True
       .Send
        End If
     End With
     Set objOutlookMsg = Nothing
     Set objOutlook = Nothing
     Set objOutlookAttach = Nothing
     Exit Sub
    ErrorMsgs:
     If Err.Number = "287" Then
     MsgBox "You clicked No to the Outlook security warning. " & _
     "Rerun the procedure and click Yes to access e-mail " & _
     "addresses to send your message."
     Else
     MsgBox Err.Number & " " & Err.Description
    End If
    End Sub
    I still get the "438 Object doesn't support this property or method" as soon as I select the button to send email.

Page 2 of 3 FirstFirst 123 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 03-16-2014, 02:12 PM
  2. sending email with attachment of certain file.
    By joshynaresh in forum Access
    Replies: 1
    Last Post: 02-13-2014, 05:16 AM
  3. sending specific details to pdf and email
    By blappy347 in forum Import/Export Data
    Replies: 1
    Last Post: 03-29-2013, 12:46 PM
  4. Combining 'sending mail' with 'sending a report'.
    By Mattbro in forum Programming
    Replies: 2
    Last Post: 11-25-2012, 07:42 AM
  5. Sending excel file in an email
    By Jim.H. in forum Access
    Replies: 1
    Last Post: 01-29-2012, 12:56 PM

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