Print Problems... (1 Viewer)

smtazulislam

Member
Local time
Today, 04:00
Joined
Mar 27, 2020
Messages
806
Hello everyone, good day !
I want to printout from a sub(form) as same row data, see attached picture. But its print out all entries with selected EmployeeID.
Capture.PNG

I try to code like :
Code:
Private Sub cmdPrint_Click()
On Error GoTo cmdPrint_Click_Err
If IsNull(Me.EmployeeID) Then
    MsgBox "Please select a valid record", vbOKOnly, "Data Required"
End If
   
    DoCmd.OpenReport "rptPenality", acViewPreview, "", "[AttID] = " & Me!txtAttID, acWindowNormal,
    DoCmd.Close acForm, "frmEmployee"
    DoCmd.RunCommand acCmdPrint
    Debug.Print


cmdPrint_Click_Exit:
    Exit Sub

cmdPrint_Click_Err:
    MsgBox Error$
    Resume cmdPrint_Click_Exit

End Sub
 
Last edited:

smtazulislam

Member
Local time
Today, 04:00
Joined
Mar 27, 2020
Messages
806
Make a report.
thank you for quick reply...
This is my report "rptPenality"

Edit
I am sorry I find out my problem, I dont put in the report page AttID..
 

smtazulislam

Member
Local time
Today, 04:00
Joined
Mar 27, 2020
Messages
806
You can talk me why it was print out 2 pages.
Last page is Blank with header a Box dark ink...
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 20:00
Joined
Feb 28, 2001
Messages
27,172
When you get a blank page like you described in post #4, that USUALLY means you have a form that is taller than the print margins. That is something you fix from the Page Setup options on the report.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 09:00
Joined
May 7, 2009
Messages
19,231
Code:
Private Sub cmdPrint_Click()
dim sAttID As string
On Error GoTo cmdPrint_Click_Err
If IsNull(Me.EmployeeID) Then
    MsgBox "Please select a valid record", vbOKOnly, "Data Required"
    Exit Sub
End If
   With Me.RecordsetClone
           If Not (.BOF And .EOF) Then
            .MoveFirst
        End If
        Do Until .EOF
            sAttID = sAttID & [AttID] & ", "
            .MoveNext
        Loop
    End With
    If Len(sAttID) > 0 Then
        sAttID = Left$(sAttID, Len(sAttID)-2)
        DoCmd.OpenReport "rptPenality", acViewPreview, "", "[AttID] In (" & sAttID & ")", acWindowNormal
    Else
        DoCmd.OpenReport "rptPenality", acViewPreview, "", , acWindowNormal
    End If   
    DoCmd.Close acForm, "frmEmployee"
    DoCmd.RunCommand acCmdPrint
    Debug.Print


cmdPrint_Click_Exit:
    Exit Sub

cmdPrint_Click_Err:
    MsgBox Error$
    Resume cmdPrint_Click_Exit

End Sub
 

smtazulislam

Member
Local time
Today, 04:00
Joined
Mar 27, 2020
Messages
806
When you get a blank page like you described in post #4, that USUALLY means you have a form that is taller than the print margins. That is something you fix from the Page Setup options on the report.
appreciate and thanks for exactly catched my wrong.
Yes, it is wrong page setting. fixed myself and change page setup. Now good looking and printed.
 

smtazulislam

Member
Local time
Today, 04:00
Joined
Mar 27, 2020
Messages
806
Code:
Private Sub cmdPrint_Click()
dim sAttID As string
On Error GoTo cmdPrint_Click_Err
If IsNull(Me.EmployeeID) Then
    MsgBox "Please select a valid record", vbOKOnly, "Data Required"
    Exit Sub
End If
   With Me.RecordsetClone
           If Not (.BOF And .EOF) Then
            .MoveFirst
        End If
        Do Until .EOF
            sAttID = sAttID & [AttID] & ", "
            .MoveNext
        Loop
    End With
    If Len(sAttID) > 0 Then
        sAttID = Left$(sAttID, Len(sAttID)-2)
        DoCmd.OpenReport "rptPenality", acViewPreview, "", "[AttID] In (" & sAttID & ")", acWindowNormal
    Else
        DoCmd.OpenReport "rptPenality", acViewPreview, "", , acWindowNormal
    End If  
    DoCmd.Close acForm, "frmEmployee"
    DoCmd.RunCommand acCmdPrint
    Debug.Print


cmdPrint_Click_Exit:
    Exit Sub

cmdPrint_Click_Err:
    MsgBox Error$
    Resume cmdPrint_Click_Exit

End Sub
Appreciated for your code. You code is worked.
But I have question here and hope you dont mind. I want to know and learning.
My below of code also work...
Code:
Private Sub cmdPrint_Click()
On Error GoTo cmdPrint_Click_Err
If IsNull(Me.EmployeeID) Then
    MsgBox "Please select a valid record", vbOKOnly, "Data Required"
End If
    
    'DoCmd.OpenReport "rptPenality", acViewPreview, "", "[EmployeeID] = " & Me!txtEmployeeID, acWindowNormal, "[AttID] = " & Me!txtAttID
    DoCmd.OpenReport "rptPenality", acViewPreview, "", "[AttID] = " & Me!txtAttID, acWindowNormal
    DoCmd.Close acForm, "frmEmployee"
    DoCmd.RunCommand acCmdPrint
    Debug.Print

cmdPrint_Click_Exit:
    Exit Sub

cmdPrint_Click_Err:
    MsgBox Error$
    Resume cmdPrint_Click_Exit
End Sub

Without underneath these line code this command can printing. So why I put LOOP code. Here any optionally method ?...
Dont smile like that question. I have itch to know.

Code:
With Me.RecordsetClone
           If Not (.BOF And .EOF) Then
            .MoveFirst
        End If
        Do Until .EOF
            sAttID = sAttID & [AttID] & ", "
            .MoveNext
        Loop
    End With
    If Len(sAttID) > 0 Then
        sAttID = Left$(sAttID, Len(sAttID)-2)
Thank you so much...

Another question: I want go back same sAttID when I close the report Page.
 

Users who are viewing this thread

Top Bottom