Search code examples
vbams-accessvb6activexqr-code

Making QRCode ActiveX Control for MS Access: Control Source Property


I wanted to implement a QR Code to Access2010 and I found https://github.com/yas78/QRCodeLibVBA. Referencing XLAM from Access did not work and I didn't want to insert all modules directly to Access as it makes the project messy. So I decided to create an OCX file using ancient VB6 as it seemed to be the easiest way to encapsulate all the bits together into one simple object.

Finally, I have made an OCX that has several key properties: DataString which is the string to be displayed, ByteModeCharsetName, ErrorCorrectionLevel, ForeRGB and BackRGB, there are also methods Refresh, Cls and events OnClick and OnDblClick

It works fine in VB6 apps + Excel sheets + Excel forms but it behaves weird in Access forms, reports, etc.

Everything looks as one would expect in Excel: Excel printscreen

This is how it looks in Access: MS Access printscreen

  • The custom properties are visible on the tab "Other" but they are not offered in VBA editor at all! However it does compile when entered manually.
  • Resizing control behaves weird
  • Control's Events like OnClick are not displayed at tab Event of Property Sheet

Here are my questions:

  1. Are the Controls for Access "different" than for other office apps?
  2. Why the hell are the properties hidden in editor?
  3. How to "move" some properties to other tabs (categories), for example ForeRGB to tab Format (as usual for TextBoxes etc.)?
  4. How to create ControlSource propety (on the DATA tab) which could be directly bound to a recordset without having to use a VBA? This way, I hope, I could use the control on the continuous forms as well. In fact, this is most important question.
  5. Some tips for resizing? (not important)

I think I'm pretty close to my goal but I'm stuck at this point. I know the VB6 is obsolete but after reading Creating Custom Controls for ms access 2010 VB6 seems to be easy choice. Any alternatives for writing OCX?

EDIT: Final working control is available here https://github.com/Combinatix/QRCodeAX


Solution

  • For 4. try setting your control's DataBindingBehavior to vbSimpleBound so that a scalar property (ControlSource in your case) can be bound via DataSource and DataMember properties.

    For 3. use Tools->Procedure Attributes... menu, select ControlSource in Name, expand Advanced>> and select Data in Property Category combobox. You can do the same through Object Browser (F2). Find your control, right click your property/method (should be bold) and choose Properties... context menu option. This works with methods and is more versatile than Tools->Procedure Attributes... approach.