|
-
Feb 10th, 2005, 11:20 AM
#1
Thread Starter
Junior Member
Replace OnClick Macro with VBA Code [solved]
Hello there!
I have the following problem:
I create a form with VBA (because the fields in the form are different each time the form is opened).
Also I create a control (Combobox), in which the user can select a socalled Template. After selecting a value in the combobox some fields in the form shall be filled (=execute a codesequence after raising the OnClick event).
At the moment i use this:
VB Code:
ctrl.Properties("Name") = "ComboSelectTemplate"
ctrl.Properties("OnClick") = "MacroComboSelectTemplate.OnClick"
ctrl.Properties("RowSourceType") = "Table/Query"
ctrl.Properties("RowSource") = "SELECT [" & Templates & "].[TemplateName] FROM [" & Templates & "]"
I have created a macro "MacroComboSelectTemplate" that then executes a VBA procedure.
Now I want to remove the macro-workaround and replace it by VBA code.
Anyone has an idea?
Last edited by Clywd; Feb 11th, 2005 at 10:46 AM.
Reason: [Solved]
-
Feb 10th, 2005, 12:52 PM
#2
Re: Replace OnClick Macro with VBA Code
If you go to the control in design view and click into the OnClick property, you can select to either use the
custom code builder, expression builder or assign a macro to it. I think that through code you can do it by setting its
property to "[Event Procedure]". I know if you do it in design view it takes you to a module of a procedure with the
same control name _Click, but I am unsure how it links the two if the name is different from the control name.
Any possibility of just doing it through the design window?
HTH
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Feb 11th, 2005, 03:45 AM
#3
Thread Starter
Junior Member
Re: Replace OnClick Macro with VBA Code
Thanks for your ideas!
As I create the form completely in vba code there is no design view.
Also setting the OnClick event to [Event Procedure] unfortunately does not work, as Access then tries to run the macro "Event Procedure"
-
Feb 11th, 2005, 10:45 AM
#4
Thread Starter
Junior Member
Re: Replace OnClick Macro with VBA Code
Solved it on my own; there is a function for creating procedures in modules. So I needed first to get the form's module:
VB Code:
dim mdl as module
dim result as integer
set mdl = frm.module
result = mdl.createEventProc("Click", ctrl.Name)
mdl.InsertLines result + 1, vbTab & "Msgbox ""My Code here."""
-
Feb 11th, 2005, 11:49 AM
#5
Re: Replace OnClick Macro with VBA Code [solved]
Sorry, my bad. I guess it didnt register with me on how you needed it done.
Checkout my code in CodeBank on Modifying Macro Code from VB.
Later
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|