Knowing how to access long binary data from a database table can make your database application more dynamic. Microsoft Office Access is commonly used to design local databases. Long binary data is used to store image files in a database table. You can use Visual Basic for Applications (VBA) to export the binary data to a file. VBA is a computer programming language used to automate routine tasks in Access and other Office applications.
- Skill level:
Other People Are Reading
Open Microsoft Office Access; select the "Create" tab and select "Form Design" to create a new form. Right-click the form to display the "Property Sheet."
Click the "Data" tab. Next to "Source Object," type the name of the table containing the long binary data. Select "Form" under "Selection type." Click the "Event" tab and next to "On Click" select "[Event Procedure]" to open the Microsoft Visual Basic Window.
Type the following under "Form_Load" to call the function to extract long binary data from your table to a file:
imageToFile "C:\Images\exportedImage.jpg", [Image]
Edit the path if you want the image to be exported to another path and a different file name. "[Image]" is the field in your table containing the long binary data.
Copy and paste the following function into your module:
Public Function imageToFile(strFile As String, ByRef Field As Object) As Long
Dim file Number As Integer Dim byte Data() As Byte imageToFile = 0 file Number = FreeFile Open strFile For Binary Access Write As file Number byte Data = Field Put #file Number, , byte Data imageToFile = LOF(fileNumber)
Close the "Microsoft Visual Basic" Window and right-click "Form1." Select "Form View" to export the binary data and create an image file.
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for