Wrox Programmer Forums
|
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 December 21st, 2004, 10:18 AM
Registered User
 
Join Date: Dec 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Create Controls in Run Time

Hi there,

I was trying to create a control @ run time, since there isn't the method Controls.Add, and after a little search, i found a function CreateControl, witch si limitted to create a form + control at run time, but this new form will be at design layout :
Does anyone know a way to create controls on a dynamic way, at run time?

Thanks

 
Old December 24th, 2004, 01:51 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 248
Thanks: 0
Thanked 1 Time in 1 Post
Default

Depending on what you're trying to accomplish, perhaps instead of trying to create a control at runtime, you could create the control or a set of controls in Design Mode and use the Visible property to display or hide the control.

Randall J Weers
Membership Vice President
Pacific NorthWest Access Developers Group
http://www.pnwadg.org
 
Old January 7th, 2005, 08:59 PM
Authorized User
 
Join Date: Jul 2004
Posts: 34
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via ICQ to chipset Send a message via MSN to chipset Send a message via Yahoo to chipset
Default

yes that what i do most of the time. i design the form, and set the property at run time. but its good you learn how to create contols during run-time. contols like ADODB,ADODC,textbox, but not a forms. although you can create a form at run-time but there are a lot of bugs creating forms at run-time

Arowolo
 
Old January 8th, 2005, 10:03 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

1. Open the form you want to add the control to (Form2) in design view and hide it.
2. Add a new control using the CreateControl method.
3. Toggle the form to normal view.

Also, to position the new control you are working in twips (1" * 1440), not inches.

==Code============================================ =======

' Form1 code module
Private Sub Command1_Click()

    ' used to convert inches to twips
    Const twipsPerInch As Long = 1440

    ' Open form you want to add control to
    ' in design view and hide it.
    DoCmd.OpenForm "Form2", acDesign, , , , acHidden

    ' Add new control
    With CreateControl( _
             FormName:="Form2", _
             ControlType:=acTextBox, _
             Section:=acDetail, _
             Left:=1 * twipsPerInch, _
             Top:=1 * twipsPerInch, _
             Height:=0.25 * twipsPerInch, _
             Width:=1 * twipsPerInch)

             ' set control properties
             .Name = "txtTextBox"
    End With

    ' toggle form to Normal view
    DoCmd.OpenForm "Form2"
End Sub

HTH,

Bob







Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating Controls At Run-Time robbev567 ASP.NET 2.0 Basics 2 July 25th, 2007 04:57 AM
Creating run time controls, manish_kaushik ASP.NET 2.0 Basics 1 February 10th, 2007 04:11 PM
Copying controls at run time aspadda Excel VBA 0 November 12th, 2003 01:07 PM
Adding controls at run-time !! kishore_peddi C# 0 October 13th, 2003 06:52 AM





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