Search code examples
vbams-accessqr-code

How do I implement QR code generator into a different access file?


I came accross this this post: https://www.access-programmers.co.uk/forums/threads/qrcode-image-generator.299675/ I have tried to copy and edit the VBA code and more into my own access file but it comes with error.

Edited: To generate an offline QR code in Access, I keep getting this error. It happens on load and unload form. Access Error

I am trying to implement the QR code generator into my own access program. This is the onLoad code: it's the exact same and all paths are still the same.

    Dim rsParent As DAO.Recordset2
Dim rsChild As DAO.Recordset2
Dim fld As DAO.Field2
Dim strExcel As String

strExcel = CurrentProject.Path & "\QRCode.xlsm"
If Dir(strExcel) = "" Then
    Set rsParent = CurrentDb.OpenRecordset("tblQRSheet", dbOpenDynaset)
    rsParent.MoveFirst
    Set rsChild = rsParent.Fields("attachment").Value
    Set fld = rsChild.Fields("FileData")
    fld.SaveToFile strExcel
    Set fld = Nothing
    rsChild.Close
    rsParent.Close
    Set rsChild = Nothing
    Set rsParent = Nothing
End If
If Dir(CurrentProject.Path & "\QRCodeImages", vbDirectory) = "" Then
    MkDir CurrentProject.Path & "\QRCodeImages"
End If

Set gxlApp = CreateObject("Excel.Application")
Set gxlWB = gxlApp.Workbooks.Open(CurrentProject.Path & "\QRCode.xlsm", False, False)

If anyone has any ideas or can help me make this QR code generator work in my own file that would be great. I think that it has to do with the Form's Record Source.


Solution

  • That error implies that you are using types (classes) that are not defined. You have to add the references for it to work. Probably the DAO reference is missing in your project. Go to Tools->References and select "Microsoft DAO 3.6 Object Library". Also the "Microsoft Excel Object Library" might be needed, even if the sample code uses an Object to create the Excel application.

    In case this works but you still cannot generate QR codes, consider using an external executable that does just that, and call it using something like:

    Dim strCmd As String : strCmd = """" & CurrentDBDir() & "\qrcode.exe"" -o " & """" & myFile & """" & " -s 10 -l H " & """" & strCode & """"
    ShellWait strCmd
    

    Where ShellWait is the utility created by Terry Kreft