Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create an "On-Click" procedure progmatically

Status
Not open for further replies.

mike777

Programmer
Jun 3, 2000
387
US
I've just learned how to create forms and add controls to them via VBA.
Can anyone help me create procedures for the controls?
For example:

Sub Mike()
dim frm as form, ctl as control
set frm=createform
set ctl=createcontrol(frm.name,accommandbutton)
end sub

That all works well for me. What I can't seem to get is then how to create a procedure that runs when the user clicks the command button.

Thanks for any help you can provide.

-Mike
 
oops...I think I just got it.
Code:
Sub Mike()
dim frm as form, ctl as control
set frm=createform
set ctl=createcontrol(frm.name,accommandbutton)
frm.module.insertlines [line #], [string]
end sub
Pretty sure that's it.
 
OK, maybe I spoke too soon.
It's working OK, the only problem is, when the code is finished executing the VBA editor is left standing open, and is the selected application window on thedesktop. Weird.
This is true even if I close the VBA editor, and call the procedure from a command button on a form.
Any suggestions?
Thanking you in advance.
-Mike
 
I know you must think I'm crazy answering my own questions. It's OK, I am.
I found it: In the form, where you call the code that adds the code to the class module, enter:
Code:
VBE.MainWindow.Visible=False
Works like a charm.
Hope this helps somebody.
-Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top