Stop stop code in access entering print preview mode (1 Viewer)

Jaydee-187

Registered User.
Local time
Today, 16:47
Joined
Apr 23, 2017
Messages
9
Hi, I would like this code to generate the report without entering print preview mode nor trying to print. Thank you

Code:
Private Sub cmdPreview_Click()
On Error GoTo Err_Handler
    '******************Filter report to a date range
    
    Dim strReport As String
    Dim strDateField As String
    Dim strWhere As String
    Dim lngView As Long
    Const strcJetDate = "\#mm\/dd\/yyyy\#"
    
    strReport = "rptSummaryFoodEaten"  'report name
    strDateField = "[ShiftDate]" 'field name
    lngView = acViewPreview     'Use acViewNormal to print instead of preview.
    
    'Build the filter string.
    If IsDate(Me.txtStartDate) Then
        strWhere = "(" & strDateField & " >= " & Format(Me.txtStartDate, strcJetDate) & ")"
    End If
    If IsDate(Me.txtEndDate) Then
        If strWhere <> vbNullString Then
            strWhere = strWhere & " AND "
        End If
        strWhere = strWhere & "(" & strDateField & " < " & Format(Me.txtEndDate + 1, strcJetDate) & ")"
    End If
    
    'Close the report if already open
    If CurrentProject.AllReports(strReport).IsLoaded Then
        DoCmd.Close acReport, strReport
    End If
    
    'Open the report.
    Debug.Print strWhere
    DoCmd.OpenReport strReport, lngView, , strWhere

Exit_Handler:
    Exit Sub

Err_Handler:
    If Err.Number <> 2501 Then
        MsgBox "Error " & Err.Number & ": " & Err.Description, vbExclamation, "Cannot open report"
    End If
    Resume Exit_Handler
End Sub
 

isladogs

MVP / VIP
Local time
Today, 16:47
Joined
Jan 14, 2017
Messages
18,186
Change the line:
lngView = acViewPreview

to one of the other options: e.g. acViewDesign / acViewLayout / acViewReport

BTW what happened to your last post which I was about to look at but its disappeared!
This was part of an email I got an hour or so ago:

Jaydee-187 has just replied to a thread you have subscribed to entitled - Generating a report between date ranges - in the General forum of Access World Forums.

This thread is located at:
https://www.access-programmers.co.uk/forums/showthread.php?t=293616&goto=newpost

Here is the message that has just been posted:
***************

---Quote (Originally by Uncle Gizmo)---
I will add my two cents worth when I think it might do some good if that's what you mean.

Have you tried putting something like --- Between [StartDate] and [EndDate] in the query builder grid?
---End Quote---
Ok, Thanks for the suggestion.

I have uploaded my db and if you have the time, I'd appreciate your help.
***************
 

Jaydee-187

Registered User.
Local time
Today, 16:47
Joined
Apr 23, 2017
Messages
9
Change the line:


to one of the other options: e.g. acViewDesign / acViewLayout / acViewReport

BTW what happened to your last post which I was about to look at but its disappeared!
This was part of an email I got an hour or so ago:

Thank you for your help and concern on the last post.
It didn't get off on the right note so I managed to solve it with a little help from one of the guys from this site. Much appreciated!
 

Users who are viewing this thread

Top Bottom