By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,254 Members | 2,365 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,254 IT Pros & Developers. It's quick & easy.

creating controls:text boxes, labels on a report on the fly, runtime.

P: 11
I have created a report in design mode. However, some of the fields i need are dynamic. That is, i have a series of fields text boxes mostly that must show up only as needed. I also have some labels that also should dynamic depending on the text boxes. I first tried createReportcontrol during the OnOpen event for the report,and when i tried to run it, it would give me an error 2147, that i must be in design view in order to create or delete controls. Someone in google said that one way to avoid this would be to make the call to CreateReportControl from another form, before calling the docmd.open report command. I tried that and i got another error, 2451, that i cannot create a control on an unopened report. Then someone in google was saying that's not a good idea anyway. And instead to create enough controls and just making visible as i need them. I can do that, however, i still need to have the labels created dynamically because the labels refer to types of text boxes and i need to present them as i need them. Is there a way to create label controls on the fly for a report? And is there another call besides createreportcontrol or createcontrol that i can use?
Nov 14 '08 #1
Share this Question
Share on Google+
5 Replies


FishVal
Expert 2.5K+
P: 2,653
Hello,

You may look at Create Dynamic Report using VBA.

On the other hand changing report controls visibility may be a better solution:
Hide no data fields in access reports
"Moving" a line in a Report based on 2 conditions

Regards,
Fish
Nov 14 '08 #2

P: 11
Thanks. I will look at those posts.
Nov 14 '08 #3

P: 11
I am trying this:
for each c in me.controls
if typeOf C is textbox then
me.controls(c.tag).visible = true
me.controls(c.tag).setfocus //it crashes
Me.lblMoneyOrder.top = me.txppay1.top
endif
next
I get the run-time error 2478 indicating that the application does not allow you to use this method in the current view.

I am trying to load data to the text boxes based on some criteria. I wanted to create the textboxes on the fly but i kept getting errors such as 2147 that does not allow me to create a control on a report unless it is a design view.

How can i set the focus on a report control on the fly?
Nov 14 '08 #4

missinglinq
Expert 2.5K+
P: 3,532
I am trying this:

for each c in me.controls
if typeOf C is textbox then
me.controls(c.tag).visible = true
me.controls(c.tag).setfocus //it crashes
Me.lblMoneyOrder.top = me.txppay1.top
endif
next

How can i set the focus on a report control on the fly?
Trying this code WHERE?

To my knowledge, you cannot set focus to a control in a report, no matter what view it's in, nor can you use SetFocus in Design View on a form.

I get the run-time error 2478 indicating that the application does not allow you to use this method in the current view.

I am trying to load data to the text boxes based on some criteria. I wanted to create the textboxes on the fly but i kept getting errors such as 2147 that does not allow me to create a control on a report unless it is a design view.
You cannot create controls in Access, whether on a form or on a report, unless that form or report is opened in Design View! This is not going to change, no matter how mant times you try to do it.

To be honest, I think the best piece of advice you've gotten was from the person who told you that this wasn't a good idea. I personally consider it to be a horrendously bad idea. Trying to design and balance a report so that it presents data in a clear and professional manner is hard enough with the Design View in front of you. Trying to do it "on the fly" is really inane. You really need to think about designing your form in advance and, as has been suggested both here and elsewhere, making controls visible/invisible depending on your needs.

Welcome to Bytes!

Linq ;0)>
Nov 14 '08 #5

P: 11
Well, Right you are. I finally realized that and have now just created a bunch of controls i need and just turn them on and off (visible) as i wish. I found a solution in this site for my problem of moving the labels to the required positions on the fly. But what i was hoping to do was to create a variable but limited number of text boxes depending on the requirements. Thanks.
Nov 15 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.