Search code examples
sqlvbams-accessole

Microsoft Access 2016 OLE Object & Binary export


I'm trying to write some VBA code to generate a text file containing SQL INSERT statements for all records in a table in an Access database (accdb). The table has an OLE Object field and a Binary field. I can't seem to get them written to the text file properly; I mostly get question marks(?). I've search for solutions and found some possible ideas but none worked.

If any one has suggestions, I will be very appreciative of any help that you can provide.

Miguel


Solution

  • I actually found an solution following some more searching:

    Function ByteArrayToHex(B() As Byte) As String
        Dim n As Long, I As Long
        
        ByteArrayToHex = Space$(2 * (UBound(B) - LBound(B)) + 2)
        n = 1
        For I = LBound(B) To UBound(B)
           Mid$(ByteArrayToHex, n, 2) = right$("00" & Hex$(B(I)), 2)
           n = n + 2
        Next
        ByteArrayToHex = "0x" & ByteArrayToHex
    End Function
    

    Michael