Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Closed Thread
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 14th, 2004, 09:10 AM
lxu lxu is offline
Authorized User
Join Date: Oct 2003
Location: , , .
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,

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

Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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

All times are GMT -4. The time now is 04:55 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.