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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ofilha
    New Member
    • Jul 2007
    • 11

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

    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 createReportcon trol 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 CreateReportCon trol 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 createreportcon trol or createcontrol that i can use?
  • FishVal
    Recognized Expert Specialist
    • Jun 2007
    • 2656

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

    Comment

    • ofilha
      New Member
      • Jul 2007
      • 11

      #3
      Thanks. I will look at those posts.

      Comment

      • ofilha
        New Member
        • Jul 2007
        • 11

        #4
        I am trying this:
        for each c in me.controls
        if typeOf C is textbox then
        me.controls(c.t ag).visible = true
        me.controls(c.t ag).setfocus //it crashes
        Me.lblMoneyOrde r.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?

        Comment

        • missinglinq
          Recognized Expert Specialist
          • Nov 2006
          • 3533

          #5
          Originally posted by ofilha
          I am trying this:

          for each c in me.controls
          if typeOf C is textbox then
          me.controls(c.t ag).visible = true
          me.controls(c.t ag).setfocus //it crashes
          Me.lblMoneyOrde r.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.

          Originally posted by ofilha
          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)>

          Comment

          • ofilha
            New Member
            • Jul 2007
            • 11

            #6
            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.

            Comment

            Working...