前言:
公司的Office 2016 Professional Plus是没有微软提供的BarCode Control,两个解决办法
1、使用网页生成二维码,Access访问web获取二维码
2、用VBA写一个源生二维码控件
很遗憾,没有时间支持我研究第二个方案,所以我直接引用别人写好的库,采用第一种方法
以下是详细步骤:
Step1、
搭建二维码生成网站(https://www.itorian.com/2015/11/qr-code-generation-and-verification.html)
Step2、
Access访问获取二维码
Option Compare Database
Option Explicit
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
Public Function DownloadFile(URL As String, LocalFilename As String) As String
Dim lngRetVal As Long
lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
If lngRetVal = 0 Then
If Dir(LocalFilename) <> vbNullString Then
DownloadFile = LocalFilename
End If
End If
End Function
Private Sub Command29_Click()
Dim result
result = DownloadFile("http://SGHZ001032667/GenerateQR.aspx?text=pur:" & TxtQR.Value, "C:\Users\dmu1szh\Desktop\1.jpg")
If Len(result) > 0 Then
Image43.Picture = result
Else
MsgBox "Unable to download the file,or the source url doesn't exist."
End If
End Sub