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 July 1st, 2004, 09:27 AM
Registered User
 
Join Date: Jun 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Create Control in Existing Form

Is it possible to create ne control (textbox) in a form i am already in at runtime ? Everything i find on the web seems to be about creating new forms and new controls in them

 
Old July 1st, 2004, 01:24 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

While you can add a new control to an existing form at run-time, I can't think of how you could add a new control to the form you are already in (i.e., in which the code is currently executing). The form would first have to be toggled to design view, which closes the form, and while the code continues to run in the form's code module, the CreateControl method can't then recieve the form's name as an argument.

I've included code to add a control to an existing form when it is opened from another form. Perhaps you can modify it for your purposes.

- open the form you want to add the control to (Form2) in design view and hide it.
- add a new control using the CreateControl method.
- 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
Placing existing control in newly added container morbidreich Beginning VB 6 1 December 27th, 2007 11:14 PM
I want to create button control in runtime. wongsak VS.NET 2002/2003 3 October 20th, 2006 07:10 AM
Adding existing and non-existing attributes spencer.clark XSLT 5 July 27th, 2005 04:02 PM
Create new dataset from two existing datasets wmoy C# 3 June 28th, 2005 09:33 AM
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.