Creating controls via code

David Mack

Registered User.
Local time
Today, 20:17
Joined
Jan 4, 2000
Messages
53
Hi,

I have spent the past few days working on a form on-the-fly which is a questionaire. I have been able to add labels, option groups, (what a challenge that was) and other controls with a little sweat. Now I'm stuck. I have been trying to assign a function or subprocedure contained in a module to the OnClick event of a control via code. I have tried just about everything. How is it done? It's not in any of my developer books or in the help facility that I can find.

The snipet of code:

Set optAnswer = CreateControl("frmOptions", acOptionGroup, , "", "", left, top)
With optAnswer
.ControlSource = i
.DefaultValue = 3
.Name = "option" & i
.Height = 300
.Width = 1700
'Handle nulls passed by the array...
.Tag = IIf(IsNull(arrayrst(5, i - 1)), "", arrayrst(5, i - 1))
.ControlTipText = IIf(IsNull(arrayrst(4, i - 1)), "", arrayrst(4, i - 1))
.OnClick '''''''WHAT GOES HERE?''''''''
End With

The form is programically created and opened up in acDesign mode. All the other properties seem to set fine. Do I have to set the "Contains Module" property first maybe?

Thanks,

Dave
 
boblarson,

Thank you very much. I still cannot find it in the help files. My interim solution was to create a new procedure via code which is very messy to implement, though it works...Got the idea from Susann Novalis' "Access 97 Macro and VBA Handbook"

Dim frm As Form
Set frm = Forms!frmOptions
Dim mdl As Module, lngReturn As Long, str As String
Set mdl = frm.Module
Dim labelname As String 'need to pass each ctl name for the event to be added to
labelname = .Name 'set it here before .Name references the form's name
With frm
lngReturn = mdl.CreateEventProc("click", labelname)
str = str & "MsgBox """ & IIf(IsNull(arrayrst(4, i - 1)), "", arrayrst(4, i - 1)) & ""
mdl.InsertLines lngReturn + 1, str
End With

HTH

Dave


[This message has been edited by David Mack (edited 04-30-2001).]
 

Users who are viewing this thread

Back
Top Bottom