• VBA help

    Author
    Topic
    #471982

    I have a database where I want to put in some VBA coding.

    Basically I want to print a report – advance to the next record on the form – print the document – loop until all records are printed

    I dont have a lot of experience in VBA but I am guessing it would be structered somethign like this. The part I am missing is how to make it loop threw all the records.

    Private Sub Command92_Click()
    On Error GoTo Command92_Click_Err

    DoCmd.OpenReport “Agent Report Card”, acViewNormal, “”, “”, acNormal
    DoCmd.GoToRecord , “”, acNext

    Command92_Click_Exit:
    Exit Function

    Command92_Click_Err:
    MsgBox Error$
    Resume Command92_Click_Exit

    Viewing 0 reply threads
    Author
    Replies
    • #1247256

      you might like to give your button a meaningfull name instead of just leaving it as ‘Command92’.

      try this

      Code:
      On Error Resume Next
      
      Do Until Err.Number  0
          DoCmd.OpenReport "Agent Report Card"
          If Err.Number = 2501 Then Err = 0 ' there was no data
          DoCmd.GoToRecord , , acNext
      Loop

      when you get to the end of the form’s records the docmd.gotorecord will raise an error and the code will stop.

    Viewing 0 reply threads
    Reply To: VBA help

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: