Hi
Can anyone shed light on what I'm doing wrong with the code below. I'm trying to get the size of each pdf file within folder c:\attachments\ and insert this (with file name) into table "temp". I get "file not found" when I try to run it.
I've also tried using FileLength = MyFile.size instead of FileLength = FileLen(MyFile), but I get invalid qualifier
I'm a newbie to VBA so any help would be much appreciated.
Public Function ImportPDF()
Dim MyFile As String
Dim file As String
Dim FileLength As Long
Dim db As Database
Dim sSQL As String
Set db = CurrentDb()
If Right(strPath, 1) <> "" Then strPath = strPath & ""
If strFilter = "" Then strFilter = "*"
MyFile = Dir$("c:\attachments\" & "*." & "pdf")
Do While MyFile <> ""
FileLength = FileLen(MyFile)
sSQL = "INSERT INTO temp(attachment, size) VALUES(""" & MyFile & """, """ & FileLength & """)"
db.Execute sSQL, dbFailOnError
MyFile = Dir$
Loop
Forms![attachment]![attachment sub2].Requery
Error_Handler_Exit:
On Error Resume Next
Set db = Nothing
Exit Function
Error_Handler:
MsgBox "The following error has occured" & vbCrLf & vbCrLf & _
"Error Number: " & Err.Number & vbCrLf & _
"Error Source: ImportDirListing" & vbCrLf & _
"Error Description: " & Err.Description, vbCritical, _
"An Error has Occured!"
Resume Error_Handler_Exit
End Function
Can anyone shed light on what I'm doing wrong with the code below. I'm trying to get the size of each pdf file within folder c:\attachments\ and insert this (with file name) into table "temp". I get "file not found" when I try to run it.
I've also tried using FileLength = MyFile.size instead of FileLength = FileLen(MyFile), but I get invalid qualifier
I'm a newbie to VBA so any help would be much appreciated.
Public Function ImportPDF()
Dim MyFile As String
Dim file As String
Dim FileLength As Long
Dim db As Database
Dim sSQL As String
Set db = CurrentDb()
If Right(strPath, 1) <> "" Then strPath = strPath & ""
If strFilter = "" Then strFilter = "*"
MyFile = Dir$("c:\attachments\" & "*." & "pdf")
Do While MyFile <> ""
FileLength = FileLen(MyFile)
sSQL = "INSERT INTO temp(attachment, size) VALUES(""" & MyFile & """, """ & FileLength & """)"
db.Execute sSQL, dbFailOnError
MyFile = Dir$
Loop
Forms![attachment]![attachment sub2].Requery
Error_Handler_Exit:
On Error Resume Next
Set db = Nothing
Exit Function
Error_Handler:
MsgBox "The following error has occured" & vbCrLf & vbCrLf & _
"Error Number: " & Err.Number & vbCrLf & _
"Error Source: ImportDirListing" & vbCrLf & _
"Error Description: " & Err.Description, vbCritical, _
"An Error has Occured!"
Resume Error_Handler_Exit
End Function