Print Report (1 Viewer)

M. Mudassar

New member
Local time
Today, 12:39
Joined
Dec 29, 2020
Messages
1
Hi to all... I'm making a database for private sector. I need a report button which actually print data between two dates. And also filter data according to the given factory which I select in combobox.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 07:39
Joined
Feb 19, 2013
Messages
16,553
welcome to the forum - what is your question? if it is how to do it there are many ways. All depends on how you want to do it

Please explain in more detail what you are trying to do
 

Dreamweaver

Well-known member
Local time
Today, 07:39
Joined
Nov 28, 2005
Messages
2,466
You will need a way of allowing your user to add the two dates Either Input boxes or a custom form.
I use this behind a form

The code below uses the openArgs to print or preview a report the form is also linked to my reports table and is filtered by the calling sub
Code:
Dim stDocName As String, StrWhere As String
On Error GoTo HandleErr

    If Not IsDate(Me.txt_From) Or Not IsDate(Me.txt_To) Then
        MsgBox "You must add a beginning and ending date", vbInformation + vbOKOnly, "Invalid dates"
        Exit Sub
    End If
    If Me.txt_From > Me.txt_To Then MsgBox "The Beginning date cannot be later then the end date", vbInformation + vbOKOnly, "Incorrect Dates": Exit Sub

    Me.Visible = False
    'This has two mods of opersation
    If Not IsNothing(Me.OpenArgs) Then
        StrWhere = "int([ItemDate]) BETWEEN " & Format(Me![txt_From], "\#" & "mm/dd/yyyy" & "\#") & " AND " & Format(Me![txt_To], "\#" & "mm/dd/yyyy" & "\#")
        Select Case Me.OpenArgs
            Case 1
                DoCmd.OpenReport Me.TxtObjectName, acPreview, , StrWhere
            Case 2
                DoCmd.OpenReport Me.TxtObjectName, acViewNormal, , StrWhere
         End Select
        DoCmd.Close acForm, Me.Name
    End If
  
HandleExit:
    Exit Sub
  
HandleErr:
    Select Case Err.Number
        Case 2501, 2212
            Exit Sub 'So as the forms been told to close just exit all good
        Case Else
            MsgBox Err.Number & vbCrLf & Err.Description
            Resume HandleExit
        Resume
    End Select
 

Users who are viewing this thread

Top Bottom