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 | 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
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 21st, 2004, 10:18 AM
Registered User
Join Date: Dec 2004
Location: , , .
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?


Reply With Quote
  #2 (permalink)  
Old December 24th, 2004, 01:51 PM
Friend of Wrox
Join Date: Nov 2004
Location: Seattle, WA, .
Posts: 248
Thanks: 0
Thanked 1 Time in 1 Post

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
Reply With Quote
  #3 (permalink)  
Old January 7th, 2005, 08:59 PM
Authorized User
Join Date: Jul 2004
Location: lagos, ikeja, Nigeria.
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

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

Reply With Quote
  #4 (permalink)  
Old January 8th, 2005, 10:03 AM
Friend of Wrox
Join Date: Jun 2003
Location: , , USA.
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts

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



Reply With Quote

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
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

All times are GMT -4. The time now is 06:39 AM.

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