Alex & Access

December 8, 2010

Programmatically create ActiveX control on Access form

Filed under: Access — access @ 8:49 am

To create new control on Access form in design mode you can use CreateControl function, works fine for native controls, but for AcitveX controls (acCustomControl argument) it creates only empty container. Where can you set which control you want to create? The trick is to copy OLEData property from existing control to just created:

Dim frm As Form, ctl As ControlSet
frm = Forms("MyForm") 'Make sure it is opened in design mode
Set ctl = CreateControl(frm.Name, acCustomControl, acDetail, , , 100, 100, 200, 200)
ctl.OleData = frm("cmd001").OleData 'cmd001 already exists on that form, or other opened form
ctl.Name = "cmd002" 

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: