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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problems with CreateControl inside Class

Status
Not open for further replies.

peebatron10k

Programmer
Jun 16, 2007
3
0
0
GB
I am trying to write a class module which will create a series on controls on any given form with the end result being a menu. the class is called on the load event of a form:

Private Sub Class_Initialize()

Dim initFrm As String
Dim X As Integer
Dim p(1 To 17) As Control

'kill instance if parent not form
If Application.CurrentObjectType <> acForm Then
Class_Terminate
End If

initFrm = Application.CurrentObjectName

'enter design
DoCmd.OpenForm initFrm, acDesign

For X = 1 To 17

Application.CreateControl initFrm, acLabel, acDetail, , , , 56 + (X * 226), , 223
appFormat X, initFrm
appLbl X, initFrm
appEvent X, initFrm

Next X

'enter normal
DoCmd.OpenForm initFrm, acNormal

End Sub


(appFormat, appLbl and appEvent are seperate Subs within the class)

The first time it hits the CreateControl method it tells me that: "Microsoft Access can't add, rename or delete the controls you requested" (this is err code 29054)

I would normally try and figure this one out but the error message doesn't give away any clues as to what is the problem and the Debug button is disabled.

Does anyone know where I am going wring? Any help is greatly appreciated :D


peebatron10k
 
It sounds like the form is not in design view when the controls are being added. I see that you have a line to open the form in design view but I have a hunch it won't work because it is being performed during the call from the form's on Open event.

Does your code work if you modify it to open a form in design view and add the controls instead of calling it on the on open event?

 
As it turns out the x, y, width and height parameters for the CreateControl function, although all optional are nested so if ...

Application.CreateControl initFrm, acLabel, acDetail, , , , 56 + (X * 226), , 223

becomes...

Application.CreateControl initFrm, acLabel, acDetail, , , 0, 56 + (X * 226), 0, 223

the code works absoluteley fine :D
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top