Page 2 of 2 FirstFirst 12
Results 16 to 18 of 18
  1. #16
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    And the IE doesn't allow navigation of the 3 images?



    What is code to open images in IE?
    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
    DevState is offline Advanced Beginner
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2018
    Posts
    35
    In module:
    Code:
    Public Function OpenFirstAttachmentAsTempFile(ByRef rstCurrent As DAO.Recordset, ByVal strFieldName As String) As StringDim rstChild As DAO.Recordset2
    Dim fldAttach As DAO.Field2
    Dim strFilePath As String
    Dim strTempDir As String
    
    
    strTempDir = Environ("Temp") ' Get the Temp directory from the environment variable.
    If Right(strTempDir, 1) <> "\" Then strTempDir = strTempDir & "\" ' Make sure the path always ends with a backslash.
        Set rstChild = rstCurrent.Fields(strFieldName).Value ' the .Value for a complex field returns the underlying recordset.
        strFilePath = strTempDir & rstChild.Fields("FileName").Value ' Append the name of the first (and only) attached file to temp dir.
        If Dir(strFilePath) <> "" Then ' the file already exists--delete it first.
        VBA.SetAttr strFilePath, vbNormal ' remove any file attributes (e.g. read-only) that would block the kill command.
        VBA.Kill strFilePath ' delete the file.
    End If
    Set fldAttach = rstChild.Fields("FileData") ' The binary data of the file.
    fldAttach.SaveToFile strFilePath
    rstChild.Close ' cleanup
    VBA.Shell "Explorer.exe " & Chr(34) & strFilePath & Chr(34), vbNormalFocus ' Use Windows Explorer to launch the file.
    End Function 'OpenFirstAttachmentAsTempFile
    Code:
    Private Sub lstAtt_DblClick(Cancel As Integer)
    
    
    Dim dbs As DAO.Database
    Dim rst As DAO.Recordset
    Const strTable = "tblAttachments" '<- Replace this with your table with attachment
    Const strField = "Attachments" '<- Replace this with the fieldname of your attachment
    Set dbs = CurrentDb
    Set rst = dbs.OpenRecordset("SELECT * FROM tblAttachments WHERE vNumber=" & lblID.Caption)
    'rst.MoveNext ' Uncomment this line to go to the 2nd row in the Table.
    OpenFirstAttachmentAsTempFile rst, strField
    rst.Close
    End Sub

    No it does not allow to flip through each attachment. I think it's a matter of being stuck on only viewing the first "record".

  3. #18
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Code does what it is written to do, open only first attachment. Modify to pass the selected file name to function and run FindFirst on the child recordset.

    I modified code to a single procedure.
    Code:
     Private Sub lstAtt_DblClick(Cancel As Integer)
     Dim dbs As DAO.Database
     Dim rst As DAO.Recordset
     Dim rstChild As DAO.Recordset2
     Dim fldAttach As DAO.Field2
     Dim strFilePath As String
     Dim strTempDir As String
     Set dbs = CurrentDb
     Set rst = dbs.OpenRecordset("SELECT * FROM tblAttachments WHERE vNumber=" & Me.lblID.Caption)
     Set rstChild = rst.Fields("Attachments").Value
     rstChild.FindFirst "FileName='" & Me.lstAtt & "'"
     strTempDir = Environ("Temp") ' Get the Temp directory from the environment variable.
     If Right(strTempDir, 1) <> "\" Then strTempDir = strTempDir & "\" ' Make sure the path always ends with a backslash.
     strFilePath = strTempDir & rstChild.Fields("FileName").Value ' Append the name of the selected attached file to temp dir.
     If Dir(strFilePath) <> "" Then ' the file already exists--delete it first.
         VBA.SetAttr strFilePath, vbNormal ' remove any file attributes (e.g. read-only) that would block the kill command.
         VBA.Kill strFilePath ' delete the file.
     End If
     Set fldAttach = rstChild.Fields("FileData") ' The binary data of the file.
     fldAttach.SaveToFile strFilePath
     rstChild.Close ' cleanup
     rst.Close
     VBA.Shell "Explorer.exe " & Chr(34) & strFilePath & Chr(34), vbNormalFocus ' Use Windows Explorer to launch the file.
     End Sub
    I find it odd to reference a label control to get parameter.
    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.

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

Similar Threads

  1. Attachments
    By DevState in forum Forms
    Replies: 2
    Last Post: 01-14-2019, 08:06 AM
  2. Replies: 2
    Last Post: 01-29-2014, 03:19 PM
  3. attachments
    By chiefmsb in forum Forms
    Replies: 0
    Last Post: 07-12-2011, 07:32 AM
  4. attachments
    By chiefmsb in forum Access
    Replies: 0
    Last Post: 07-10-2011, 07:38 PM
  5. attachments
    By chiefmsb in forum Access
    Replies: 0
    Last Post: 07-08-2011, 03: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