sirhannick
Registered User.
- Local time
- Today, 11:05
- Joined
- Jun 18, 2013
- Messages
- 20
My database was working fine until I split the database and now I'm having issues with this function:
It's getting stuck on the "strFilePath = strTempDir & rstChild.Fields("FileName").Value" line. The debugger says that there is no reord. The strTempDir is correct. I am not the original writer of this code so I don't understand it 100%. I am assuming that the issue has to with linking to the database. Any help please?
Code:
Public Function OpenFirstAttachmentAsTempFile(ByRef rstCurrent As DAO.Recordset, ByVal strFieldName As String) As String
Dim rstChild As DAO.Recordset2
Dim fldAttach As DAO.Field2
Dim strFilePath As String
Dim strTempDir As String
'On Error GoTo ErrorHandlingCode
'-------------------------Export Attached Text File to Temp Folder-------------------------------
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.
OpenFirstAttachmentAsTempFile = strFilePath 'Return temp file path
Exit Function
ErrorHandlingCode:
MsgBox ("There was a problem in reading the EEPROM text attachment. Please contact your administrator.")
End Function 'OpenFirstAttachmentAsTempFile
It's getting stuck on the "strFilePath = strTempDir & rstChild.Fields("FileName").Value" line. The debugger says that there is no reord. The strTempDir is correct. I am not the original writer of this code so I don't understand it 100%. I am assuming that the issue has to with linking to the database. Any help please?