Results 1 to 2 of 2

Thread: VBA help

  1. #1
    3 Star Lounger
    Join Date
    Feb 2004
    Location
    Kitchener, Ontario, Canada
    Posts
    228
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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



  2. #2
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Brisbane, Queensland, Australia
    Posts
    387
    Thanks
    0
    Thanked 1 Time in 1 Post
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •