Results 1 to 2 of 2
  1. #1
    fishen88 is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Jan 2013
    Posts
    3

    Utilizing multilist and command button to open up stored attachments

    Hi,


    I currently have a multi-select list that is populated with several options. I also have a table that has excel spreadsheet stored to each different record via an attachment field. I am wanting to have a command button on my form that will open up the attached file for the selected record. My current code is as follows. The second allotment of code I tried to transpose from an example I found on the web. Any brilliant ideas?




    Private Sub cmdfm_click()
    'On Error GoTo Err_cmdfm_click
    Dim strwhere As String
    Dim ctl As Control
    Dim varItem As Variant
    If Me.lstreport.ItemsSelected.Count = 0 Then
    MsgBox "Must select at least 1 employee"
    Exit Sub
    End If
    Set ctl = Me.lstreport
    For Each varItem In ctl.ItemsSelected
    strwhere = strwhere & ctl.ItemData(varItem) & ","
    Next varItem
    strwhere = Left(strwhere, Len(strwhere) - 1)
    Dim retval As Variant
    If tblfmvsfm.failuremodevsfailuremode > "" Then
    retval = bimShellOpenFile(tblfmvsfm.failuremodevsfailuremod e, vbNormalFocus) ' vbNormalFocus True
    Else
    MsgBox "There is no fiel to view."

    exit_cmdopenreport_click:
    Exit Sub
    'Err_cmdfm_click:
    'MsgBox Err.Description
    'Resume exit_cmdfm_click
    End Sub


    Function GetOpenFile(Optional varDirectory As Variant, _
    Optional varTitleForDialog As Variant) As Variant
    ' Here's an example that gets an Access database name.
    Dim strFilter As String
    Dim lngFlags As Long
    Dim varFileName As Variant
    ' Specify that the chosen file must already exist,
    ' don't change directories when you're done
    ' Also, don't bother displaying
    ' the read-only box. It'll only confuse people.
    lngFlags = ahtOFN_FILEMUSTEXIST Or _
    ahtOFN_HIDEREADONLY Or ahtOFN_NOCHANGEDIR
    If IsMissing(varDirectory) Then
    varDirectory = ""
    varDirectory = strDefaultDir ' set to the default


    End If


    If IsMissing(varTitleForDialog) Then
    varTitleForDialog = ""
    End If
    ' Define the filter string and allocate space in the "c"
    ' string Duplicate this line with changes as necessary for
    ' more file templates.
    ' strFilter = ahtAddFilterItem(strFilter, "Access (*.mdb)", "*.MDB;*.MDA")

    strFilter = ahtAddFilterItem(strFilter, "All Files (*.*)", "*.*")
    strFilter = ahtAddFilterItem(strFilter, "Adobe PFD (*.PFD)", "*.PDF")
    strFilter = ahtAddFilterItem(strFilter, "JPEGs (*.jpg)", "*.jpg;*.jpeg")



    ' Now actually call to get the file name.
    varFileName = ahtCommonFileOpenSave( _
    OpenFile:=True, _
    InitialDir:=varDirectory, _
    Filter:=strFilter, _
    Flags:=lngFlags, _
    DialogTitle:=varTitleForDialog)
    If Not IsNull(varFileName) Then
    varFileName = TrimNull(varFileName)
    End If
    GetOpenFile = varFileName
    End Function

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    What is wrong - error message, wrong results, nothing happens? Have you step debugged? Review link at bottom of my post for guidance on debug techniques.
    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.

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

Similar Threads

  1. command button to open attachments
    By tommyried in forum Access
    Replies: 1
    Last Post: 06-20-2012, 07:51 AM
  2. Command button open url
    By patrickmcdiver in forum Programming
    Replies: 2
    Last Post: 03-06-2012, 11:08 AM
  3. Command button to open Report
    By swagger18 in forum Programming
    Replies: 0
    Last Post: 11-17-2011, 02:56 AM
  4. Use a command button to open a form
    By johnpaul in forum Forms
    Replies: 24
    Last Post: 09-23-2010, 12:29 PM
  5. Replies: 1
    Last Post: 07-07-2010, 11:06 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