How to create a NEW! textbox in a form using VBA?

  • Thread starter Marcel Drost via AccessMonster.com
  • Start date
M

Marcel Drost via AccessMonster.com

I now the code to handle the size and height of a textbox.

Bijschrift32.Visible = True
Bijschrift32.Height = 2
Bijschrift32.Left = 8
Bijschrift32.Top = 1

But how to create a new textbox using vba??
Real help would be if I could copy one using a loop... The loop; I can build but how to create a new one...

ANY help is sincirely appreciated! because I'm stuck a real long time now..

*****************************************
* This message was posted via http://www.accessmonster.com
*
* Report spam or abuse by clicking the following URL:
* http://www.accessmonster.com/Uwe/Abuse.aspx?aid=d07f61933d724e1aa5343eafce9e3781
*****************************************
 
J

Jamie Richards

Hi,

This code is from A2K help. NB: Controls cannot be created on a form at
runtime.

Sub NewControls()
Dim frm As Form
Dim ctlLabel As Control, ctlText As Control
Dim intDataX As Integer, intDataY As Integer
Dim intLabelX As Integer, intLabelY As Integer

' Create new form with Orders table as its record source.
Set frm = CreateForm
frm.RecordSource = "Orders"
' Set positioning values for new controls.
intLabelX = 100
intLabelY = 100
intDataX = 1000
intDataY = 100
' Create unbound default-size text box in detail section.
Set ctlText = CreateControl(frm.Name, acTextBox, , "", "", _
intDataX, intDataY)
' Create child label control for text box.
Set ctlLabel = CreateControl(frm.Name, acLabel, , _
ctlText.Name, "NewLabel", intLabelX, intLabelY)
' Restore form.
DoCmd.Restore
End Sub


Jamie
 
M

Marcel Drost via AccessMonster.com

Thanks a lot that was very helpfull,

Could you please tell me how to repeat the trick in a existing report?

(The trick making a new textbox using vba) As far as I understand (sunday is my programming day, is that new textboxs are created by controls and controls must be created by modules and cannot be created in a report itself)

Still mucho gracias; I will take a very carefull look at it Sunday (with a friend of mine)

Marcel

*****************************************
* A copy of the whole thread can be found at:
* http://www.accessmonster.com/uwe/Forum.aspx/access-formscoding/18700
*
* Report spam or abuse by clicking the following URL:
* http://www.accessmonster.com/Uwe/Abuse.aspx?aid=251ea2f0a3504d1ab7c1f4b581c04691
*****************************************
 
D

Douglas J. Steele

I can't imagine any situations where it's really necessary to dynamically
add a new control.

Far easier is to add all of the possible controls you might need, and only
make the ones you actually need visible.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Marcel Drost via AccessMonster.com said:
I now the code to handle the size and height of a textbox.

Bijschrift32.Visible = True
Bijschrift32.Height = 2
Bijschrift32.Left = 8
Bijschrift32.Top = 1

But how to create a new textbox using vba??
Real help would be if I could copy one using a loop... The loop; I can
build but how to create a new one...
 
M

Marcel Drost via AccessMonster.com

That's aboout 68 (rows)*5 (columns) of them. there IS! a structure in the report... So If I could dynamically create them it would be very usefull...

It's for those scanned fill-in forms. Like

Fill in what you need

1,1 {} ............ 5,1 ()
2,1 {}
.....
.....
57,1 {}
68,1 {} ........... 5,68 ()

You normally use a pen, only humans make too much errrors and the receiver of those papers does not accept the digital data; SO:

A computer must print out (over) these forms. (print the necesseray, not always the same, boxes black...)
I have the algorithm (loop), now I need is the dynamic creation of the black textbox (or copy number one)....

So!!! This sounds like a situation where dynamic controls can be useful, right??

*****************************************
* A copy of the whole thread can be found at:
* http://www.accessmonster.com/uwe/Forum.aspx/access-formscoding/18700
*
* Report spam or abuse by clicking the following URL:
* http://www.accessmonster.com/Uwe/Abuse.aspx?aid=28331494eba746c2ab66782bd290e0bd
*****************************************
 
D

Douglas J. Steele

Sorry, I still think it's better to create all of the controls initially,
and only show those that you need.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Marcel Drost via AccessMonster.com said:
That's aboout 68 (rows)*5 (columns) of them. there IS! a structure in the
report... So If I could dynamically create them it would be very usefull...
It's for those scanned fill-in forms. Like

Fill in what you need

1,1 {} ............ 5,1 ()
2,1 {}
....
....
57,1 {}
68,1 {} ........... 5,68 ()

You normally use a pen, only humans make too much errrors and the receiver
of those papers does not accept the digital data; SO:
A computer must print out (over) these forms. (print the necesseray, not
always the same, boxes black...)
I have the algorithm (loop), now I need is the dynamic creation of the
black textbox (or copy number one)....
 
D

Douglas J. Steele

You have to open the form in Design mode and use the CreateControl function.

The example in http://support.microsoft.com/?id=210595 uses CreateForm, so
it's not obvious that the form needs to be in Design mode.


You cannot do this with an MDE, or if your users are using the run-time
 
M

Marcel Drost via AccessMonster.com

Thanks, this what was I was looking for... Now I understand the problem and I can solve it..

Still Listening to advice, I've already made the whole report, and will use the visisble trick...

Still thanks..

Marcel

*****************************************
* A copy of the whole thread can be found at:
* http://www.accessmonster.com/uwe/Forum.aspx/access-formscoding/18700
*
* Report spam or abuse by clicking the following URL:
* http://www.accessmonster.com/Uwe/Abuse.aspx?aid=d4ee5fa70d304fee8ebf24756891f457
*****************************************
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top