retriving blobs file into

Forum home » Delegate support and help forum » Microsoft Access VBA Training and help » Retriving Blobs to File into a table

Retriving Blobs to File into a table

resolvedResolved · Urgent Priority · Version 2016

Manny has attended:
Access Intermediate course
Access Advanced course

Retriving Blobs to File into a table

hello All,

I am migrating my access DB into a sql server. One of the big issues i have come across is the storage of screenshots. this is imperative and is used as audit for a challenge process.

I have been able to store the pasted screenshot to file, using a function "BlobToFile".
- In a form a user copy and pastes a screenshot
- Once a user confirms the screenshot, the function (below) pushes the object to the company shared drive and in the background, the file name is stored in another text file [SupportName]

This works fine and so does the the function BlobToFile when is is able to recall the blob from the [SupportName].

The issue is, the BlobToFile and the FiletoBlob seem to only work on the userform and on one record. I would like to recall all the files to a table on any given day (in order to run reports off of it) and then i can go ahead and delete the rows after all the reports have been run (knowing that all of the images are stored on the disk and the [SupportName] stores the file path]

Is there any way i am able to bulk import all the necessary images i require? I appreciate this is difficult over the net but that is the crux of the matter, being able to import all the images into a table, in access, as an OLE object, to run reports.


Here are the functions:

---------------------------------------------------------

Public Function BlobToFile(strFile As String, ByRef Field As Object) As Long
On Error GoTo BlobToFileError
Dim nFileNum As Integer
Dim abytData() As Byte
BlobToFile = 0
nFileNum = FreeFile
Open strFile For Binary Access Write As nFileNum
abytData = Field
Put #nFileNum, , abytData
BlobToFile = LOF(nFileNum)

BlobToFileExit:
If nFileNum > 0 Then Close nFileNum
Exit Function

BlobToFileError:
MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical, _
"Error writing file in BlobToFile"
BlobToFile = 0
Resume BlobToFileExit

End Function


-------------------------------------------------------

Public Sub FileToBlob(strFile As String, ByRef Field As Object)
On Error GoTo FileToBlobError

If Len(Dir(strFile)) > 0 Then
Dim nFileNum As Integer
Dim byteData() As Byte

nFileNum = FreeFile()
Open strFile For Binary Access Read As nFileNum
If LOF(nFileNum) > 0 Then
ReDim byteData(1 To LOF(nFileNum))
Get #nFileNum, , byteData
Field = byteData
End If
Else
MsgBox "Error: File not found", vbCritical, _
"Error reading file in FileToBlob"
End If

FileToBlobExit:
If nFileNum > 0 Then Close nFileNum
Exit Sub

FileToBlobError:
MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical, _
"Error reading file in FileToBlob"
Resume FileToBlobExit

End Sub


------------------------------------------



Public Function FileToBlobFunct(strFile As String)
On Error GoTo FileToBlobFunctError

If Len(Dir(strFile)) > 0 Then
Dim nFileNum As Integer
Dim byteData() As Byte

nFileNum = FreeFile()
Open strFile For Binary Access Read As nFileNum
If LOF(nFileNum) > 0 Then
ReDim byteData(1 To LOF(nFileNum))
Get #nFileNum, , byteData
FileToBlobFunct = byteData
End If
Else
MsgBox "Error: File not found", vbCritical, _
"Error reading file in FileToBlob"
End If

FileToBlobFunctExit:
If nFileNum > 0 Then Close nFileNum
Exit Function

FileToBlobFunctError:
MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical, _
"Error reading file in FileToBlob"
Resume FileToBlobFunctExit
End Function







RE: Retriving Blobs to File into a table

Hi Manny,

Thank you for the forum question.

It is not something I have done before, but I have found a link, which will hopefully point you in the right direction.

https://stackoverflow.com/questions/45659706/using-vba-to-import-a-large-number-of-attachment-into-microsoft-access

Interesting functions.


Kind regards

Jens Bonde
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

RE: Retriving Blobs to File into a table

thanks so much, Jens. I will try this today and see if it works. fingers crossed

RE: Retriving Blobs to File into a table

Good luck Manny,

I hope it is a success


Kind regards

Jens Bonde
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

RE: Retriving Blobs to File into a table

hey jens,

i have had no luck unfortuantely, i have tried various different methods to do this but still not luck.

any other ideas?

Manny

RE: Retriving Blobs to File into a table

Hi Manny,

I am sorry that have been waiting a while for an answer, but what you want is for sure not simple.

I have discussed the question with my colleagues with VBA knowledge, I have searched the web. I have been through several forums without luck.

I always tell my clients that everything is possible when it comes to VBA, but I am sorry, I have to give up on this one.


Kind regards

Jens Bonde
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

RE: Retriving Blobs to File into a table

Hi Jens,

I agree, this was far too difficult and tried my best also to make this work. I got very close a couple of times. What i have done is to push all the screen shots into a pdf on the company shared drive at the end of the day and then remove all the screenshots out of Access, then compacted.

Whilst not ideal it saves huge amount of space and has managed to make a 1.5GB database under 40Mb, which is great news for me.

Appreciate your help as always!
Manny

Fri 22 Feb 2019: Automatically marked as resolved.

 

Training courses

 

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Access tip:

Display current date & time in column of any width

The worksheet function =NOW() returns the current date & time. When entered into a column which is not wide enough to display the value NOW returns, the cell displays ###

View all Access hints and tips


Server loaded in 0.11 secs.