Linking files to an access table
Hi All - I've been struggling for a while now trying to get a selected file to attach to an ole field in a table. I can capture all other info but can't get the class & source into the ole field. I'll try to explain what I'm doing - I have a form with a subform that tracks complaints, the main form has the general info on the case and the subform displays a table with a link (& other info) to related files (basically correspondance, word docs, pictures etc). I can browse for a file using an api call, and I can capture the user, time, document path etc but I don't know how to put the source into the ole field of the table? - There are lots of examples on how to link to a form using object.sourcedoc but none that I know of with tables.
All I want to do is be able to launch the file from the subform.
Does anyone know how to do this? I have attached a code snippet which might help explain my situation. Yes - I know there's no error handling, I'll get round to that if i can sort this out :o)
Private Sub AttachObject_Click()
Dim WmProject As Database 'Object database variable
Dim objRst As DAO.recordset 'Object recordset variable
Dim strFilter As String
Dim lngflags As Long
Dim varFileName As Variant 'Variable to hold file path
Set WmProject = CurrentDb ' Create a database object and assign current database to that object
'Create a recordset assign table and open table
Set objRst = WmProject.OpenRecordset("DocumentTable", dbOpenDynaset)
strFilter = "All Files (*.*)" & vbNullChar & "*.*" _
& vbNullChar & "All Files (*.*)" & vbNullChar & "*.*"
lngflags = tscFNPathMustExist Or tscFNFileMustExist _
Or tscFNHideReadOnly
'Assign file path to variable
varFileName = tsGetFileFromUser( _
fOpenFile:=True, _
strFilter:=strFilter, _
rlngflags:=lngflags, _
strDialogTitle:="Choose File To Attach")
If IsNull(varFileName) Then
Else
With objRst
.AddNew
!CSRRef = Me.Form!ID 'Capture id field insert into table to use as link
!OLEDocumentType = ???????????? Need help here Ole filed to store class and link details
!DocumentPath = varFileName
!Date = Date
!User = CsrUser()'Capture current user
.Update 'Update the table
End With
End If
objRst.Close
Set objRst = Nothing
Me.Requery 'Requery the form to update changes
End Sub
Cheers
William
__________________
William
|