View Single Post
  #1 (permalink)  
Old January 5th, 2004, 03:24 PM
mtrtxs mtrtxs is offline
Registered User
Join Date: Jan 2004
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default creating controls on the fly


I am trying creating forms on the fly from code to replace a clutter of too many small forms in a DB.

I hope to use code to add command buttons, and I want to attach code to them, and to be able to close the forms unsaved - without "save or not" dialog boxes and prompts. I want to just use the forms, then ditch them.

My code so far:

Private Sub NewControls()

Dim frm As Form
Dim ctlLabel As Control
Dim ctlText 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

Set frm = CreateForm ' Create new form

frm.RecordSource = "TblOrders" '''' with Orders table as record source

' size for textbox
intDataX = 2000 ' top, left, width - position, size new controls
intDataY = 100
intDataZ = 3000 ' width of textbox is set here - third size argument

' Create unbound default-size text box in detail section.
Set ctlText = CreateControl(frm.Name, acTextBox, , "", "shipname", intDataX, intDataY, intDataZ)

' size for lable
intLabelX = 100
intLabelY = 100
intLabelZ = 1 ' hmmmm....odd, width of label is dependent
' on text within - rather than the argument here - not my
' prime question though.

' 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"
End With

' line below to build a command button on the fly isn't working
' I don't know why - help - I just get errors

setBtnTest = CreateControl(frm.Name, acCommandButton, , , , 100, 100, 100, 100)

a = frm.Name

DoCmd.OpenForm a, acNormal
DoCmd.MoveSize , , 5555, 5555

End Sub



Reply With Quote