Vb. Open report error based on a form that is just opened.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Eddie Nugroho
    New Member
    • Nov 2014
    • 7

    Vb. Open report error based on a form that is just opened.

    I have a main form, FrmMain. Put a button to open "FrmPrice". Works OK. In FrmPrice I put another button that open a report, ReportOffer, based on FrmPrice. Works OK too.

    I tried to put a button in FrmMain to directly open FrmPrice and then open ReportOffer, the code failed in calculated control with #error.

    Code:
    DoCmd.Openform "FrmPrice"
    DoCmd.Openreport "ReportOffer"
    Tried to put me.Requery. Didn't help.
    Please help... Thanks
    *Access 2007
    Last edited by zmbd; Dec 2 '14, 06:36 PM. Reason: [Z{Please use the [CODE/] button to format posted script and formatted text - Please read the FAQ}]
  • Seth Schrock
    Recognized Expert Specialist
    • Dec 2010
    • 2965

    #2
    When you say you open ReportOffer based on FrmPrice, what do you mean? Do you have to enter/select a value for a control in FrmPrice that has to do with the calculated field in ReportOffer?

    Comment

    • Eddie Nugroho
      New Member
      • Nov 2014
      • 7

      #3
      Yes, correct. It works OK if I open the report AFTER the form is fully opened.

      Comment

      • twinnyfo
        Recognized Expert Moderator Specialist
        • Nov 2011
        • 3662

        #4
        Eddie,

        I believe the problem comes that you are trying to open the two objects essentially simultaneously. If ReportOffer only runs after FrmPrice is opened, you must actually wait until the form fully loads before the report can use any data on that Form.

        Seth, do you know of a way to check the Form's load status programmaticall y? If not, I think one way would be to send a value to the Form and in the OnLoad event of the Form, if that value is True, to open the Report, otherwise, wait for the user to click the button.

        This is one of the challenges with using Form values as part of a Record Source for any other object in Access--it is not a "wrong" process, but there are several challenges you must be careful for, and this is one of them.

        Comment

        • Seth Schrock
          Recognized Expert Specialist
          • Dec 2010
          • 2965

          #5
          My guess is that the value in FrmPrice isn't getting entered/selected and thus it's not available for the report. One option would be to move the control from FrmPrice to FrmMain and that would eliminate the step of opening FrmPrice. Another option would be to open FrmPrice as a Dialog Box which stops code execution in the calling form until it closes, which would allow you to select the value necessary for the calculation of the report. Or you could use code to set the value in FrmPrice before you open the report.

          However, I don't believe that the problem is that the report is opening before the form is completely open. I have coded many times where I set a control value immediately after using the DoCmd.OpenForm command. This wouldn't work if the form hadn't finished opening. I think that the control is empty when the report is calling for it, meaning the user hasn't supplied the value.

          Comment

          • Eddie Nugroho
            New Member
            • Nov 2014
            • 7

            #6
            Yes, the control is empty when the report is opened. Hence the error. Tried the acDialog, but I couldn't get it to work (open the report without closing the form). Thanks anyway

            Comment

            • Eddie Nugroho
              New Member
              • Nov 2014
              • 7

              #7
              Thank you all... Solved the issue. In the main form I write DoCmd.OpenForm "FrmPrice". Below this line I wait for the control in the opened FrmPrice to get its value:

              Code:
              While Forms!FrmPrice!ctrlXxx = 0
                 DoEvents
              Wend
              Then the open report command line. It works.
              Thanks again...

              I had used the DoEvents before, but without waiting for the control to get its value.
              Last edited by zmbd; Dec 2 '14, 06:37 PM. Reason: [Z{Please use the [CODE/] button to format posted script and formatted text - Please read the FAQ}]

              Comment

              • twinnyfo
                Recognized Expert Moderator Specialist
                • Nov 2011
                • 3662

                #8
                Eddie,

                Glad you found a solution that worked.!

                Comment

                • Eddie Nugroho
                  New Member
                  • Nov 2014
                  • 7

                  #9
                  Thanks for your attention. Appreciate it.

                  Comment

                  Working...