Running Code Through a Loop?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • martin DH
    New Member
    • Feb 2007
    • 114

    #1

    Running Code Through a Loop?

    Hello all,
    I'm looking for some help with what I believe will be a loop. I have the following code on a form that updates a field in a table and then prints a report for the current record. My form can be open with more than one record, however, and I would like this set of code to run for each record on the form. As always, many thanks for your tips!

    [CODE=vb]Private Sub cmdPrint_Click( )
    'Immediately prints one copy of the current letter.
    On Error GoTo Err_cmdPrint_Cl ick

    If Me.txtLetter = "Receipt Confirmation" Then
    'sets checkbox to checked if letter is for Receipt Confirmation
    DoCmd.OpenQuery "qryUpdateRecCo nf"
    DoCmd.OpenRepor t "rptTemplateLet ters", acViewNormal
    Else
    DoCmd.OpenRepor t "rptTemplateLet ters", acViewNormal
    End If

    Exit_cmdPrint_C lick:
    Exit Sub
    Err_cmdPrint_Cl ick:
    MsgBox Err.Description
    Resume Exit_cmdPrint_C lick
    End Sub[/CODE]

    Software: Access 2003
    Form: frmEditTemplate
    Form's Record Source: qryEditTemplate

    Martin
  • PianoMan64
    Recognized Expert Contributor
    • Jan 2008
    • 374

    #2
    Originally posted by martin DH
    Hello all,
    I'm looking for some help with what I believe will be a loop. I have the following code on a form that updates a field in a table and then prints a report for the current record. My form can be open with more than one record, however, and I would like this set of code to run for each record on the form. As always, many thanks for your tips!

    [CODE=vb]Private Sub cmdPrint_Click( )
    'Immediately prints one copy of the current letter.
    On Error GoTo Err_cmdPrint_Cl ick

    If Me.txtLetter = "Receipt Confirmation" Then
    'sets checkbox to checked if letter is for Receipt Confirmation
    DoCmd.OpenQuery "qryUpdateRecCo nf"
    DoCmd.OpenRepor t "rptTemplateLet ters", acViewNormal
    Else
    DoCmd.OpenRepor t "rptTemplateLet ters", acViewNormal
    End If

    Exit_cmdPrint_C lick:
    Exit Sub
    Err_cmdPrint_Cl ick:
    MsgBox Err.Description
    Resume Exit_cmdPrint_C lick
    End Sub[/CODE]

    Software: Access 2003
    Form: frmEditTemplate
    Form's Record Source: qryEditTemplate

    Martin
    can you send what is in the query setup, this will make a difference as to how I'll setup the lookup and what will need to be loop.

    Also include any tables that are being bound to the reports and any data sources that you're wanting to pull all this records from?

    Thanks,

    Joe P.

    Comment

    Working...