Vba 为MS Access制作QRCode ActiveX控件:控件源属性
我想实现一个二维码来访问2010年,我发现。从Access引用XLAM不起作用,我不想将所有模块直接插入Access,因为这会使项目变得混乱。 因此,我决定使用古老的VB6创建一个OCX文件,因为这似乎是将所有位封装到一个简单对象中的最简单方法 最后,我制作了一个OCX,它有几个关键属性:Vba 为MS Access制作QRCode ActiveX控件:控件源属性,vba,ms-access,vb6,activex,qr-code,Vba,Ms Access,Vb6,Activex,Qr Code,我想实现一个二维码来访问2010年,我发现。从Access引用XLAM不起作用,我不想将所有模块直接插入Access,因为这会使项目变得混乱。 因此,我决定使用古老的VB6创建一个OCX文件,因为这似乎是将所有位封装到一个简单对象中的最简单方法 最后,我制作了一个OCX,它有几个关键属性:DataString这是要显示的字符串,ByteModeCharsetName,ErrorCorrectionLevel,ForeRGB和BackRGB,还有一些方法Refresh,Cls和事件OnClick和
DataString
这是要显示的字符串,ByteModeCharsetName
,ErrorCorrectionLevel
,ForeRGB
和BackRGB
,还有一些方法Refresh
,Cls
和事件OnClick
和ondblick
它在VB6应用程序+Excel工作表+Excel表单中工作正常,但在Access表单、报表等中表现怪异
在Excel中,一切看起来都与预期的一样:
这是Access中的外观:
- 自定义属性在选项卡“其他”上可见,但在VBA编辑器中根本不提供它们!但是,当手动输入时,它会编译
- 调整控件大小的行为很奇怪
- 控件的事件(如
)不会显示在属性页的选项卡事件中OnClick
ForeRGB
到选项卡格式(与文本框等的常规方式相同)ControlSource
属性(在“数据”选项卡上),该属性可以直接绑定到记录集,而无需使用VBA?我希望,通过这种方式,我也可以对连续形式使用控件。事实上,这是最重要的问题编辑:此处提供最终工作控件一种非常不同且不太麻烦的方法是在线生成二维码并下载它们以显示在(绑定)图片控件中 我写了一篇关于显示在线图像的文章: 当然,需要一些代码,但比您在GiHub中提到的代码要少得多,尽管这里有很多代码需要完整列出 它使用此函数检索图像:
' Download (picture) file from a URL of a hyperlink field to a
' (temporary) folder, and return the full path to the downloaded file.
'
' This can be used as the control source for a bound picture control.
' If no Folder is specified, the user's IE cache folder is used.
'
' Typical usage in the RecordSource for a form or report where Id is
' the unique ID and Url is the hyperlink field holding the URL to
' the picture file to be displayed:
'
' - to a cached file where parameter Id is not used:
'
' Select *, UrlContent(0, [Url]) As Path From SomeTable;
'
' - or, where Id is used to create the local file name:
'
' Select *, UrlContent([Id], [Url], "d:\somefolder") As Path From SomeTable;
'
' Then, set ControlSource of the bound picture control to: Path
'
' 2017-05-28. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function UrlContent( _
ByVal Id As Long, _
ByVal Url As String, _
Optional ByVal Folder As String) _
As Variant
Const NoError As Long = 0
Const Dot As String = "."
Const BackSlash As String = "\"
Dim Address As String
Dim Ext As String
Dim Path As String
Dim Result As String
' Strip leading and trailing octothorpes from URL string.
Address = HyperlinkPart(Url, acAddress)
' If Address is a zero-length string, Url was not wrapped in octothorpes.
If Address = "" Then
' Use Url as is.
Address = Url
End If
If Folder = "" Then
' Import to IE cache.
Result = DownloadCacheFile(Address)
Else
If Right(Folder, 1) <> BackSlash Then
' Append a backslash.
Folder = Folder & BackSlash
End If
' Retrieve extension of file name.
Ext = StrReverse(Split(StrReverse(Address), Dot)(0))
' Build full path for downloaded file.
Path = Folder & CStr(Id) & Dot & Ext
If DownloadFile(Address, Path) = NoError Then
Result = Path
End If
End If
UrlContent = Result
End Function
它马上就起作用了:
可以在GitHub上找到完整的代码:逐个回答您的问题:
CustomControl.object
属性访问要封装的控件的对象Dim qrObj As QRCode
Set qrObj = QR.Object
CustomControl.SizeToFit
通常可以正常工作当然,有些我认为不可能的事情可以通过修改ActiveX控件的源代码来实现。尝试设置控件,以便标量属性(
ControlSource
在您的示例中)可以通过DataSource
和DataMember
属性绑定
三个人。使用
Tools->Procedure Attributes…
菜单,在名称中选择ControlSource
,展开Advanced>
并在属性类别
组合框中选择数据。您可以通过对象浏览器(F2)执行相同的操作。找到控件,右键单击属性/方法(应为粗体),然后选择属性…
关联菜单选项。这适用于方法,比工具->过程属性…
方法更通用。我以前使用过场景1-下载和显示。然而,这并不能真正回答我的问题。我当前的OCX工作几乎完美,在将其放入新的access数据库后,它只需要一行VBAQR.DataString=Me!SomeField
。此外,该数据库保持独立于互联网。我的问题的目的是了解如何将Access特定功能插入OCX。我只使用过第三方OCX,没有VB6,所以我不知道,对不起。只是想确定一下,你知道另一个选择。此外,OCX的使用也减少了,因为它们通常不支持64位访问。。。你是说Access的CustomControl
包装器必须了解我的OCX的道具,然后才能将它们传播到正确的属性选项卡?我有源代码,我可以用它做我想做的(几乎)是的,wqw刚刚分享了一个答案,我已经简单地测试了你的建议,并将我的数据字符串绑定到控制源代码。太棒了!但是Burst Access现在拒绝将表单显示为连续的:绑定了ActiveX控件或嵌入对象绑定到数据源的表单不能将其DefaultView属性设置为连续表单。我有一种不好的感觉。。。有什么建议吗?@Combinatrix在我的回答中分享过,将军
Dim qrObj As QRCode
Set qrObj = QR.Object