访问VBA报告打印下面的表单

时间:2016-04-19 02:30:02

标签: vba printing access-vba report

我有一个奇怪的问题,我无法解决。我将Access数据库拆分为前端和后端。我的一个表单有一系列单选按钮和一个启动按钮,允许用户选择要打开的报表。我在下面附上了我的表格照片:

Image1

当用户加载所选报告时,它将按预期打印在打印预览模式中。

Image2

但是,当用户单击左上角的“打印”按钮时,25%的时间不打印显示的报告,它会在打印预览下方打印表单。我无法解决这个问题。据我所知,打印预览具有焦点,因为用户正在点击该屏幕上的“访问打印”按钮。

正如我所说,这只发生了25%的时间,另外75%正常打印报告。如果打印不正确,没有什么不同,我无法重新解决问题,尽管看似相同的用户输入,它本身就会发生。

有人能指出我正确的方向吗?

修改 以下代码是单击“显示”按钮时运行的代码:

Dim strLibrary As String, strFromDate As String, strToDate As String, strCategory As String
Dim strBookType As String, strBook As String, strBorrower As String
Dim booBookSeperatePages As Boolean, booBorrowerSeperatePages As Boolean, booGrouped As Boolean
Dim dteFromDate As Date, dteToDate As Date
Dim strPassedArgument As String, strWhereStatement As String, strAnd As String

strFromDate = Nz(cboFromDate, "")
strToDate = Nz(cboToDate, "")

If Len(Nz(cboFromDate, "")) = 0 Then
    dteFromDate = #1/1/1980#
Else
    dteFromDate = cboFromDate
End If

If Len(Nz(cboToDate, "")) = 0 Then
    dteToDate = Date
Else
    dteToDate = cboToDate
End If

strCategory = Nz(cboCategory, "")
strBookType = Nz(cboType, "")
strBook = Nz(cboBook, "")
strBorrower = Nz(cboBorrower, "")
strLibrary = Str(fraLibrary)
booBookSeperatePages = chkBookSeperatePages
booBorrowerSeperatePages = chkBorrowerSeperatePages
booGrouped = chkGroup

strWhereStatement = ""
strAnd = ""

strPassedArgument = strLibrary & "|" & strFromDate & "|" & strToDate
If cboFromDate.Visible = True Then
    If fraReports = 20 Or fraReports = 21 Then
        strWhereStatement = strWhereStatement & strAnd & "[BorrowDate] >= #" & dteFromDate & "# And [BorrowDate] <= #" & dteToDate & "#"
    Else
        strWhereStatement = strWhereStatement & strAnd & "[CatalogueDate] >= #" & dteFromDate & "# And [CatalogueDate] <= #" & dteToDate & "#"
    End If
    strAnd = " And "
End If
If cboCategory.Visible = True Then
    If Len(cboCategory) > 0 Then
        strWhereStatement = strWhereStatement & strAnd & "[CategoryID] = " & cboCategory
        strAnd = " And "
    End If
End If
If cboType.Visible = True Then
    If Len(Nz(cboType, "")) > 0 Then
        If Nz(cboType, 0) <> 0 Then
            strWhereStatement = strWhereStatement & strAnd & "[BookTypeID] = " & cboType
            strAnd = " And "
        End If
    End If
End If
If fraLibrary.Visible = True Then
    Select Case fraLibrary
        Case 1
            strWhereStatement = strWhereStatement & strAnd & "[BookTypeHasReader] = -1"
            strAnd = " And "
        Case 2
            strWhereStatement = strWhereStatement & strAnd & "[BookTypeHasReader] = 0"
            strAnd = " And "
    End Select
End If
If cboBook.Visible = True Then
    If Len(Nz(cboBook, "")) > 0 Then
        strWhereStatement = strWhereStatement & strAnd & "[BookID] = " & cboBook
            strAnd = " And "
    End If
End If
If cboBorrower.Visible = True Then
    If fraReports = 13 Then
        If Len(Nz(cboBorrower, "")) > 0 Then
            Dim strSplitter() As String
            strSplitter = Split(cboBorrower, ", ")
            strWhereStatement = strWhereStatement & strAnd & "[AuthorSurname] = '" & strSplitter(0) & "' AND [AuthorFirstName] = '" & strSplitter(1) & "'"
            strAnd = " And "
        End If
    Else
        If Len(Nz(cboBorrower, "")) > 0 Then strWhereStatement = strWhereStatement & strAnd & "[BorrowerID] = " & cboBorrower
        strAnd = " And "
    End If
End If

If fraReports = 7 Then
    strWhereStatement = strWhereStatement & strAnd & "([Digitised] = 'No' OR [Digitised] = 'N')"
    strAnd = " And "
    strWhereStatement = strWhereStatement & strAnd & "[BookTypeDesc] = 'Tape'"
End If

If fraReports = 8 Then
    strWhereStatement = strWhereStatement & strAnd & "([ReMastered] = 'No' OR [ReMastered] = 'N')"
    strAnd = " And "
    strWhereStatement = strWhereStatement & strAnd & "[BookTypeHasReader] = True"
End If

Select Case fraReports
    Case 0      'Sorted By Title
        If booGrouped = False Then
            DoCmd.OpenReport "rptSortedByTitle", acViewPreview, , strWhereStatement, acWindowNormal, strPassedArgument
        Else
            DoCmd.OpenReport "rptSortByTitleGrouped", acViewPreview, , strWhereStatement, acWindowNormal, strPassedArgument
        End If
    Case 1      'Sorted By Author
        DoCmd.OpenReport "rptSortedByAuthor", acViewPreview, , strWhereStatement, acWindowNormal, strPassedArgument
    Case 2      'Grouped By Category
        DoCmd.OpenReport "rptGroupedByCategory", acViewPreview, , strWhereStatement, acWindowNormal, strPassedArgument
    Case 5      'Grouped By Type
        DoCmd.OpenReport "rptGroupedByType", acViewPreview, , strWhereStatement, acWindowNormal, strPassedArgument
    Case 3      'Duplicate Books
        MsgBox "Opening Duplicate Books Form...."
    Case 4
        DoCmd.OpenReport "rptRecentAdditions", acViewPreview, , strWhereStatement, acWindowNormal, strPassedArgument
    Case 7      'Books Not Yet Digitised
        DoCmd.OpenReport "rptNotDigitised", acViewPreview, , strWhereStatement, acWindowNormal, strPassedArgument
    Case 8      'Books Not Yet Remastered
        DoCmd.OpenReport "rptNotRemastered", acViewPreview, , strWhereStatement, acWindowNormal, strPassedArgument
    Case 10     'Borrower's History
        If chkBorrowerSeperatePages = True Then
            DoCmd.OpenReport "rptBorrowersHistorySeperate", acViewPreview, , strWhereStatement, acWindowNormal, strPassedArgument
        Else
            DoCmd.OpenReport "rptBorrowersHistory", acViewPreview, , strWhereStatement, acWindowNormal, strPassedArgument
        End If
    Case 11     'Book History
        If chkBookSeperatePages = True Then
            DoCmd.OpenReport "rptBookHistorySeperate", acViewPreview, , strWhereStatement, acWindowNormal, strPassedArgument
        Else
            DoCmd.OpenReport "rptBookHistory", acViewPreview, , strWhereStatement, acWindowNormal, strPassedArgument
        End If
    Case 12        'Book Lending Count
        DoCmd.OpenReport "rptBookLendingCount", acViewPreview, , strWhereStatement, acWindowNormal, strPassedArgument
    Case 13        'Book Lending Count by Author
        DoCmd.OpenReport "rptBookLendingCountAuthor", acViewPreview, , strWhereStatement, acWindowNormal, strPassedArgument
    Case 14        'Books Borrowed Count
        If strToDate <> "" And strFromDate <> "" Then
            strPassedArgument = "HistBorrowDate >=#" & strFromDate & "# AND HistBorrowDate <=#" & strToDate & "#|" & strLibrary & "|from " & strFromDate & " to " & strToDate
        ElseIf strToDate <> "" And strFromDate = "" Then
            strPassedArgument = "HistBorrowDate <=#" & strToDate & "#|" & strLibrary & "|before " & strToDate
        ElseIf strToDate = "" And strFromDate <> "" Then
            strPassedArgument = "HistBorrowDate >=#" & strFromDate & "#|" & strLibrary & "|after " & strFromDate
        Else
            strPassedArgument = "|" & strLibrary & "|"
        End If
        DoCmd.OpenForm "frmBooksBorrowedCount", acNormal, , , , acDialog, strPassedArgument
    Case 20        'Books on Loan Sorted by Title
        DoCmd.OpenReport "rptBooksOnLoanTitle", , , strWhereStatement, acWindowNormal, strPassedArgument
    Case 21        'Books on Loan Sorted by Borrower
        If chkBorrowerSeperatePages = True Then
            DoCmd.OpenReport "rptBooksOnLoanBorrowerSep", acViewPreview, , strWhereStatement, acWindowNormal, strPassedArgument
        Else
            DoCmd.OpenReport "rptBooksOnLoanBorrower", acViewPreview, , strWhereStatement, acWindowNormal, strPassedArgument
        End If
    Case 22        'Lost/Damaged Books
        strWhereStatement = strWhereStatement & strAnd & "[BookStatusID] = 3 Or [BookStatusID] = 4 Or [BookStatusID] = 7"
        DoCmd.OpenReport "rptLostDamagedBooks", acViewPreview, , strWhereStatement, acWindowNormal, strPassedArgument
    Case 23        'Statistics
        DoCmd.OpenForm "frmStatistics", acNormal, , , , acDialog
    Case 24        'Books Reserved
        DoCmd.OpenReport "rptBooksReserved", acViewPreview, , strWhereStatement, acWindowNormal, strPassedArgument
    Case 25        'List All Borrowers
        DoCmd.OpenReport "rptListAllBorrowers", acViewPreview, , strWhereStatement, acWindowNormal, strPassedArgument
End Select

0 个答案:

没有答案