Results 1 to 5 of 5
  1. #1
    4 Star Lounger
    Join Date
    Oct 2003
    Location
    Guelph, Ontario, Canada
    Posts
    428
    Thanks
    0
    Thanked 0 Times in 0 Posts

    allow bypass of code line (Access 2000 all updates)

    The following line is one line of code that is behind a <Preview> command button on a form.
    DoCmd.OpenReport "rptReceipt", acViewPreview, , "[PatID] = Forms!frmPatInfo!PatID And [PayDate] = Date() And [Printed] = False"

    The purpose of the "[Printed] = False" part is to prevent reprinting receipts that have already been printed and issued.

    However, there may be an occasion where it is necessary to go back and re-print a lost receipt. So I need code brings up a message box saying that "This receipt has already been printed. Do you want to re-print?" and if the response from the user is Yes, the code line is bypassed and in place, this line takes over (with the omission of the [Printed] = False part)...
    DoCmd.OpenReport "rptReceipt", acViewPreview, , "[PatID] = Forms!frmPatInfo!PatID And [PayDate] = Date()"

    The query behind the report is [qryPayments]. The table is [tblPayments]. I think the test would be to open the recordset for either [qryPayments] or [tblPayments] but I'm having a brain cramp as to how to set this up.

    Thanks.

    Tom

  2. #2
    4 Star Lounger
    Join Date
    Oct 2003
    Location
    Guelph, Ontario, Canada
    Posts
    428
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: allow bypass of code line (Access 2000 all updates)

    Hans
    Well, I think you understood it perfectly. Because that does the trick.

    I'm not sure I understand the "Dim vvv" part, as that doesn't seem to be used after it is declared.

    Thanks again, Hans.

    Tom

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: allow bypass of code line (Access 2000 all updates)

    I'm not sure I completely understand, but try this:

    Private Sub cmdPreview_Click()
    Dim strWhere As String
    Dim blnIncludePrinted As Boolean

    On Error GoTo ErrHandler

    strWhere = "<!t>[PatID]<!/t> = " & Me.PatID & " And <!t>[PayDate]<!/t> = Date()"

    If DCount("*", "tblPayments", strWhere & " And <!t>[Printed]<!/t> = True") > 0 Then
    If MsgBox("This receipt has already been printed. Do you want to re-print?", _
    vbYesNo + vbQuestion) = vbYes Then
    blnIncludePrinted = True
    End If
    End If

    If blnIncludePrinted = False Then
    strWhere = strWhere & " And <!t>[Printed]<!/t> = False"
    End If

    DoCmd.OpenReport "rptReceipt", acViewPreview, , strWhere
    Exit Sub

    ErrHandler:
    If Not Err = 2501 Then ' ignore canceling the report
    MsgBox Err.Description, vbExclamation
    End If
    End Sub

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: allow bypass of code line (Access 2000 all updates)

    sorry about that, you can remove that declaration (I have also done so in my previous reply). It was a left-over from something I tested and forgot to delete before posting.

  5. #5
    4 Star Lounger
    Join Date
    Oct 2003
    Location
    Guelph, Ontario, Canada
    Posts
    428
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: allow bypass of code line (Access 2000 all updates)

    Hans
    No problem. Thanks for the clarification.

    Tom

Posting Permissions

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