Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 14th, 2004, 09:10 AM
lxu lxu is offline
Authorized User
 
Join Date: Oct 2003
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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







Similar Threads
Thread Thread Starter Forum Replies Last Post
Posting a page from AJAX Tab Control dhurjati_sen C# 2 August 20th, 2007 11:05 PM
ASP. Button Control not posting back innochig ASP.NET 1.0 and 1.1 Professional 16 January 15th, 2007 05:15 PM
Create asp file on the fly mutt1170 Classic ASP Professional 1 October 31st, 2006 06:43 AM
Posting data from Control to Page bmains ASP.NET 2.0 Basics 1 December 6th, 2005 08:08 PM
Create Control, Runtime jimmyfrank Access VBA 1 January 29th, 2005 10:40 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.