More Qstn on posting"Create Control on the fly"
I read "Create Controls on the fly" posted and solved by Mtrtxs on 01/08/04. I need to create a form dynamiclly. There are labels, text boxes, buttons and a subform on the form. Please anyone give me a hint on how to create a subform by programming? Or it cannot be done this way.
Thanks for Mtrtxs's for his work and thanks in advance for any help,
chrislx
Here is his code:
Private Sub NewControls()
Dim frm As Form
Dim mdl As Module
Dim ctlLabel As Control
Dim ctlText As Control
Dim ctlText2 As Control
Dim BtnTest As Control
Dim intDataX As Integer
Dim intDataY As Integer
Dim intDataZ As Integer
Dim intLabelX As Integer
Dim intLabelY As Integer
Dim intLabelZ As Integer
Dim a As String
Dim b As String
Dim strAddCode As String
Set frm = CreateForm ' Create new form
a = frm.Name
frm.RecordSource = "TblOrders" ' with Orders table as record source
' top, left, width - position and size new controls
intDataX = 2000
intDataY = 100
intDataZ = 3000
' Create unbound text box in detail section.
Set ctlText = CreateControl(frm.Name, acTextBox, , "", "shipname", intDataX, intDataY, intDataZ)
intLabelX = 100
intLabelY = 100
intLabelZ = 1 ' hmmm...width of label
' seems to be dependent on text within
' Create child label control for text box.
Set ctlLabel = CreateControl(frm.Name, acLabel, , ctlText.Name, "Shipping Name", intLabelX, intLabelY, intLabelZ)
With frm
.DividingLines = False
.ScrollBars = False
.RecordSelectors = False
.AutoResize = True
.AutoCenter = True
.BorderStyle = 3
.Caption = "test"
.Modal = True
.ControlBox = False
.HasModule = True
End With
Set BtnTest = CreateControl(frm.Name, acCommandButton, , , "", 400, 800, 600, 600)
b = BtnTest.Name ' KEEP c is used in code to close form
Set ctlText2 = CreateControl(frm.Name, acTextBox, , "", "=date()", 2000, 500, 3000)
With ctlText2
.TextAlign = 1
End With
BtnTest.OnClick = "[Event Procedure]"
Set mdl = Forms![Form1].Module
strAddCode = ""
strAddCode = "Private Sub " & b & "_Click()" & vbCrLf
strAddCode = strAddCode & "DoCmd.Close acForm, me.name, acSaveNo"
strAddCode = strAddCode & vbCrLf
strAddCode = strAddCode & "End Sub"
With mdl
.InsertText strAddCode
End With
BtnTest.Caption = "&Close"
BtnTest.Cancel = True
DoCmd.OpenForm a, acNormal
DoCmd.MoveSize , , 8000, 8000
End Sub
|