Solved

add labels at runtime, help !!

Posted on 2004-04-02
5
221 Views
Last Modified: 2010-04-17
this code does not work in access vba, help.  please be explicit in codde examples, eg declarations and all, thanx. very much.




Dim ctlName As Control  ' in declaration section

Private Sub Command1_Click()


Set ctlName = Form1.Controls.Add("VB.TextBox", "Text1", Form1)

ctlName.Visible = True

ctlName.Top = Check1(0).Top + Check1(0).Height

End Sub
0
Comment
Question by:vbsterxx
  • 2
5 Comments
 
LVL 27

Accepted Solution

by:
jjafferr earned 250 total points
ID: 10746138
Hi vbsterxx,
try putting your delaration line, below the Private sub

Private Sub Command1_Click()
Dim ctlName As Control  ' in declaration section

Hope this helps

jaffer
0
 
LVL 2

Assisted Solution

by:rqs
rqs earned 250 total points
ID: 10747326
I've tried this on access 2000:

Private sub cmdNewControl_Click()
   Dim ctlnewbutton as Control
   Dim frmnewform as Form
   
   Set frmnewform = CreateForm()
   frmnewform.Visible = False
   Set ctlnewbutton = CreateControl(frmnewform.name, acTextBox, acDetail)

   With ctlnewbutton
       .Width = 1000
       .Height = 200
       .Left = 200
       .Top = 200
       .Name = "txtNewControl"
   End With

   DoCmd.Close acForm, frmnewform.Name, acSaveYes
End Sub

There's a catch, Access doesn't allow creation of new controls on an open form
when that particular form is not open in design view.
That's why in the code above, the control was created on another new form.
You can then attach this new form as a subform on your target form
0
 
LVL 2

Expert Comment

by:rqs
ID: 10747332
i've found a related post here, go check it out:
http://oldlook.experts-exchange.com:8080/Databases/MS_Access/Q_20726109.html
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
A short article about a problem I had getting the GPS LocationListener working.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question