Jeg benytter følgende visual basic kode til at gemme f.eks et worddokument i en access database (2007):
Dim db As DAO.Database Dim rst As DAO.Recordset Dim rstChld As DAO.Recordset2 Dim fldAttach As DAO.Field2
Set db = CurrentDb Set rst = db.OpenRecordset("tabFiler") rst.AddNew
Set rstChld = rst.Fields("Fil").Value
rstChld.AddNew Set fldAttach = rstChld.Fields("FileData") fldAttach.LoadFromFile Fil rstChld.Update rstChld.Close
rst.Update rst.Close
Jeg vil imidlertid gerne have fat i filen igen i forbindelse med afsendelse af e-mails fra databasen. Hertil benytter jeg følgende kode:
Set oLook = CreateObject("Outlook.Application") Set oMail = oLook.createitem(0)
Set rsf = CurrentDb.OpenRecordset("SELECT * FROM tabFiler" + " WHERE " + "Nr=" + CStr(600)) Fil = rsd!Fil With oMail .To = Til .body = Tekst .Subject = Emne .Attachments.Add (Fil) .Send End With
Jeg har derfor brug for at få fat i filen igen i sætningen .Attachments.Add (Fil)
Not a good idea to save files in the database, they fill far too much. Better to just have the path/filename in the dB, this would also solve your problem on attaching the file to an email.
Thank you for your answer I agree that the files will fill up in the database. On the other hand if a fil is deleted or the filename is changed you cannot access it anymore.
The solution you recommend will as I can see it restore the file to the disk and then you can use the .Attachments.Add (Fil)sentense with Fil as the name af the file just retored to the disk.
But maybe there is another way to get the file in the database without making the restore?
"* Access will compress your attached files unless those files are compressed natively. For example, JPEG files are compressed by the graphics program that created them, so Access does not compress them."
I agree that using OLE increased original size of files, using attachments is a much better method but it still fills more than just a path/filename.
I personally would still just store path/filename, of course there is a risk of the file being deleted/renamed but then there is also a risk of your dB being corrupted. So hopefully you make backups regularly :-)
"But maybe there is another way to get the file in the database without making the restore?"
To attach the file to the email I am quite sure you will need to, no matter which method you used to get file into dB, but I may be wrong.
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.