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