Setting the OnClick property of a control on a code-created form

  • Thread starter Nicholas Scarpinato
  • Start date
N

Nicholas Scarpinato

I have a form I'm creating dynamically from code. The main reason for
creating it from code is that I have no use for it after the user selects the
option from a combobox on said created form, so I want to create it, get the
user input, and kill it. My question is, how do I make a command button on
said form run a function when the user clicks it? I can't seem to figure out
how. I've tried using the following code:

Set RunProc = CreateControl(frm.Name, acCommandButton, acDetail, , , 2880,
55, 1375, 265)
RunProc.Caption = "Select Vendor"
RunProc.FontName = "Arial"
RunProc.FontSize = 8
RunProc.OnClick = "[Event Procedure]"

But nothing happens when I click the button because it doesn't have code
linked to it, even though it says "[Event Procedure]" in the OnClick event.
Is there a way to code the OnClick event of a form inside of an Access module?



(At this point, I'm seriously considering scrapping this idea due to the
fact that loading this created form takes FOREVER once it's finished... it
takes up to 20 seconds to load, which is unacceptable. But I would still like
to know if this is possible, for future reference.)
 
K

Klatuu

See VBA Help for CreateEventProc

Then, forget the whole idea. Just create the form and reuse it as necessary.
 
N

Nicholas Scarpinato

Haha... yeah, I came to that conclusion myself. Much easier to just create
the form once and reuse it.

Klatuu said:
See VBA Help for CreateEventProc

Then, forget the whole idea. Just create the form and reuse it as necessary.
--
Dave Hargis, Microsoft Access MVP


Nicholas Scarpinato said:
I have a form I'm creating dynamically from code. The main reason for
creating it from code is that I have no use for it after the user selects the
option from a combobox on said created form, so I want to create it, get the
user input, and kill it. My question is, how do I make a command button on
said form run a function when the user clicks it? I can't seem to figure out
how. I've tried using the following code:

Set RunProc = CreateControl(frm.Name, acCommandButton, acDetail, , , 2880,
55, 1375, 265)
RunProc.Caption = "Select Vendor"
RunProc.FontName = "Arial"
RunProc.FontSize = 8
RunProc.OnClick = "[Event Procedure]"

But nothing happens when I click the button because it doesn't have code
linked to it, even though it says "[Event Procedure]" in the OnClick event.
Is there a way to code the OnClick event of a form inside of an Access module?



(At this point, I'm seriously considering scrapping this idea due to the
fact that loading this created form takes FOREVER once it's finished... it
takes up to 20 seconds to load, which is unacceptable. But I would still like
to know if this is possible, for future reference.)
 
K

Klatuu

Yes.
One other thing. Creating an destroying the form repeatedly is like a bloat
supercharger.
--
Dave Hargis, Microsoft Access MVP


Nicholas Scarpinato said:
Haha... yeah, I came to that conclusion myself. Much easier to just create
the form once and reuse it.

Klatuu said:
See VBA Help for CreateEventProc

Then, forget the whole idea. Just create the form and reuse it as necessary.
--
Dave Hargis, Microsoft Access MVP


Nicholas Scarpinato said:
I have a form I'm creating dynamically from code. The main reason for
creating it from code is that I have no use for it after the user selects the
option from a combobox on said created form, so I want to create it, get the
user input, and kill it. My question is, how do I make a command button on
said form run a function when the user clicks it? I can't seem to figure out
how. I've tried using the following code:

Set RunProc = CreateControl(frm.Name, acCommandButton, acDetail, , , 2880,
55, 1375, 265)
RunProc.Caption = "Select Vendor"
RunProc.FontName = "Arial"
RunProc.FontSize = 8
RunProc.OnClick = "[Event Procedure]"

But nothing happens when I click the button because it doesn't have code
linked to it, even though it says "[Event Procedure]" in the OnClick event.
Is there a way to code the OnClick event of a form inside of an Access module?



(At this point, I'm seriously considering scrapping this idea due to the
fact that loading this created form takes FOREVER once it's finished... it
takes up to 20 seconds to load, which is unacceptable. But I would still like
to know if this is possible, for future reference.)
 

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