CreateControl

G

Guest

I am trying to add an activex control to a form using
code. I can get the control onto the form but cannot put
an ActiveX component into the control. I have the
following code which adds the custom control to the form.

Dim frm As Form
Dim ctl As CustomControl
Set frm = CreateForm
Set ctl = CreateControl(frm.Name,
acCustomControl, , "", "", 1000, 100)
'******
'Try to set the activex control
Set ctlText.Object = CreateObject
("InternetExplorer.Application")

DoCmd.Restore

Any suggestions?
 
T

TC

I'm not sure how to do that, but CreateObject is *definitely* not what you
want. CreateObject creates a running instance of the relevant appication
(IE, in your example), and returns a handle to that instance. That handle is
not something that you could ever use for the purpose you want (AFAIK).

Are there not some Class or ObjectClass props or somesuch? (I don't have
Access ere to check) Could you create the control "manually" (via the UI),
then iterate its .properties collection & check what's there?

HTH,
TC
 
J

JamesSoar

Hi

As far as I can know you can not create an ActiveX control from scratc
but but you can copy it from another form.

Dim frm As Form
Dim ctl As CustomControl
Set frm = CreateForm
Set ctl = CreateControl(frm.Name,
acCustomControl, , "", "", 1000, 100)
'******
'Try to set the activex control
Set ctl.Name = "WebBrowser0"
Set ctl.Class = "Shell.explorer.1"
Set ctl.OLEClass = "Microsoft Web Browser"




Set ctlText.Object = CreateObject
("InternetExplorer.Application")

DoCmd.Restore
 
J

JamesSoar

Hi

As far as I can know you can not create an ActiveX control from scratch
but but you can copy it from another form.

Dim frm As Form
Dim ctl As CustomControl
Set frm = CreateForm
Set ctl = CreateControl(frm.Name,
acCustomControl, , "", "", 1000, 100)
'******
'Try to set the activex control
Set ctl.Name = "WebBrowser0"
Set ctl.Class = "Shell.explorer.1"
Set ctl.OLEClass = "Microsoft Web Browser"
' The most important line coming from the other existing control
Set ctl.OLEData = Forms.Item("OtherForm").WebBrowser0.oledata

and then some DoCmd.RunCommand to save the form

Hope it helps
James




Set ctlText.Object = CreateObject
("InternetExplorer.Application")

DoCmd.Restore
 
T

TC

Just for interest, have you tried writing the oledata to a file (for
example) & then getting it back from there? That would avoid the need to
have the other form. Perhaps a set of files for commonly used controls...?

TC


JamesSoar said:
Hi

As far as I can know you can not create an ActiveX control from scratch
but but you can copy it from another form.

Dim frm As Form
Dim ctl As CustomControl
Set frm = CreateForm
Set ctl = CreateControl(frm.Name,
acCustomControl, , "", "", 1000, 100)
'******
'Try to set the activex control
Set ctl.Name = "WebBrowser0"
Set ctl.Class = "Shell.explorer.1"
Set ctl.OLEClass = "Microsoft Web Browser"
' The most important line coming from the other existing control
Set ctl.OLEData = Forms.Item("OtherForm").WebBrowser0.oledata

and then some DoCmd.RunCommand to save the form

Hope it helps
James




Set ctlText.Object = CreateObject
("InternetExplorer.Application")

DoCmd.Restore
 
J

JamesSoar

I thought about however it seems slightly complex, so I had preferred t
copy the oledata but I'll try one day !

James Soar

Just for interest, have you tried writing the oledata to a fil
(for
example) & then getting it back from there? That would avoid the nee
to
have the other form. Perhaps a set of files for commonly use
controls...?

T
 
T

TC

By coincidence, I saw a poast yesterday (or the day before) in one of the
access newsgroups, about a module that someone had written, to do the
following. It let you store an OCX (for example) in an access table, by
calling a procedure defined for that purpose. Then, whenever your database
started, another procedure in that module would check to see if that OCX was
registered on that PC. If it wasn't, the module would retrive the OCX code
from the table, write it to disk & re-register it!!

That seems like a bright idea. If you wanted, you could doubtless find that
post by googling on appropriate words in posts from the past few days.

TC


JamesSoar said:
I thought about however it seems slightly complex, so I had preferred to
copy the oledata but I'll try one day !

James Soar

Just for interest, have you tried writing the oledata to a file
(for
example) & then getting it back from there? That would avoid the need
to
have the other form. Perhaps a set of files for commonly used
controls...?

TC

 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top