Hi all,
So I'm migrating our current system away from MS access to an alternative system my final part of this is to extract all of the pdf's that have been attached to an access database.
So my code works perfect if I specify a record that I know has a pdf in but if I try to set a loop to go through them when it gets to an entry that doesent have a record then it stops the loop the code ive got so far is below, so in my example it works upto i = 929 then that doesent have a record so stops i need to jst skip over this to the next
Kind Regards Tim
So I'm migrating our current system away from MS access to an alternative system my final part of this is to extract all of the pdf's that have been attached to an access database.
So my code works perfect if I specify a record that I know has a pdf in but if I try to set a loop to go through them when it gets to an entry that doesent have a record then it stops the loop the code ive got so far is below, so in my example it works upto i = 929 then that doesent have a record so stops i need to jst skip over this to the next
Kind Regards Tim
Code:
Dim DatabasePath As String = "c:\users\u\desktop\test.accdb"
Dim AccessEngine As New Microsoft.Office.Interop.Access.Dao.DBEngine
Dim SourceRecordset As Microsoft.Office.Interop.Access.Dao.Recordset
Dim AttachmentRecordset As Microsoft.Office.Interop.Access.Dao.Recordset
Dim db As Microsoft.Office.Interop.Access.Dao.Database = AccessEngine.OpenDatabase(DatabasePath)
Dim i As Integer
For i = 920 To 2846
Label1.Text = i.ToString
SourceRecordset = db.OpenRecordset("Select * from [qrySearchContinuous] WHERE ID = " & i)
AttachmentRecordset = SourceRecordset.Fields("Field1").Value
While Not AttachmentRecordset.EOF
Dim AttachmentFileName As String = AttachmentRecordset.Fields("FileName").Value.ToString
Dim AttachmentPath As String = "c:\users\u\desktop\Test\" & i & ".pdf"
AttachmentRecordset.Fields("FileData").SaveToFile(AttachmentPath)
AttachmentRecordset.MoveNext()
End While
SourceRecordset.Close()
SourceRecordset = Nothing
AttachmentRecordset = Nothing
Next
db.Close()
db = Nothing