on print tick the checkbox as printed (1 Viewer)

lookforsmt

Registered User.
Local time
Today, 09:32
Joined
Dec 26, 2011
Messages
672
HI! I am trying hard to get this accomplished but somehow not able to achieve. Perhaps doing something wrong.
Below is the code i have on my on click form to view the report and a msgbox that prompts me whether i want to print the report.

Can anyone help me and let me know what i am doing wrong.
thanks

Code:
Private Sub cmd_Print_Click()
    
    Dim strDocName As String
    Dim strLinkCriteria As String
    Dim myform As Form
    Dim pageno As Integer
    Dim i, p
    
    pageno = Me.CurrentRecord
    Set myform = Screen.ActiveForm
    
        strDocName = "rpt_Data_Entry"
        strLinkCriteria = "[SrId] = forms![frm_Data_Entry]![SrId]"
        
    DoCmd.RunCommand acCmdSaveRecord
    DoCmd.SelectObject acForm, frm_Data_Entry, True
    DoCmd.OpenReport strDocName, acViewPreview, , strLinkCriteria
           
    If Me.Dirty Then
    If (Me.SrId < 0) Then

    Else
        
    If MsgBox("Do you want to print this voucher?" & Chr(13) & _
    "", vbYesNo, "Process Type") = 7 Then
      
     Me.Undo
     For i = 1 To p

Next i

    Me.Requery
    
    End If
    End If
    End If
    
End Sub
 

Orthodox Dave

Home Developer
Local time
Today, 06:32
Joined
Apr 13, 2017
Messages
218
Hi,

Code:
 If MsgBox("Do you want to print this voucher?" & Chr(13) & _
    "", vbYesNo, "Process Type") = 7 Then
This is followed by nothing that would print the voucher. In any case 7 equates to "No".

Try this:
Code:
 If MsgBox("Do you want to print this voucher?" & Chr(13) & _
    "", vbYesNo, "Process Type") = vbYes Then
Docmd.SelectObject acReport, strDocName 
DoCmd.RunCommand acCmdPrint
 

lookforsmt

Registered User.
Local time
Today, 09:32
Joined
Dec 26, 2011
Messages
672
Hi! Thank you for your response, i have done as you mentioned but there seems to be no difference.
On click opens the report without asking if i want to print the report of not.

i am looking for avoiding duplicating the print, so some kind of alert that this report is already printed so the user should not print again and only unless when the report is destroyed due to the printer issue.

Is this possible in the first place.?
 

AccessBlaster

Registered User.
Local time
Yesterday, 22:32
Joined
May 22, 2010
Messages
5,941
lookforsmt:

It sounds like you want to update a Boolean field in your table to true or -1 if the print job is complete.

In one of my projects I use code like this behind a button. But you need confirmation and logic to check if the print actually happened.

Code:
Private Sub btnPrint_Click()

DoCmd.SetWarnings False

[B]DoCmd.RunSQL "UPDATE tblInv SET tblInv.Counted = -1 WHERE tblInv.ID = " & Me.ID & ";"
[/B]DoCmd.RunSQL "UPDATE tblInv SET tblInv.DateModifide = Now() WHERE tblInv.ID = " & Me.ID & ";"
Me.Requery

DoCmd.SetWarnings True

End Sub
 

lookforsmt

Registered User.
Local time
Today, 09:32
Joined
Dec 26, 2011
Messages
672
Thanks AccessBlaster

Thats right i want to update the field. based on your feedback.

i have created a new table " tblInv" with field ( ID; Counted & DateModifide )

I put your code on the form which opens the report but i have encountered below error:
Compile error: Member or data member not found

any suggestions if i am doing wrong.
 

AccessBlaster

Registered User.
Local time
Yesterday, 22:32
Joined
May 22, 2010
Messages
5,941
Yeah my example will not work for you as your fields names differ from the example. I only wanted you to confirm to the readers that your looking to update a Boolean field.

Sorry for the confusion.
 

lookforsmt

Registered User.
Local time
Today, 09:32
Joined
Dec 26, 2011
Messages
672
thanks for the clarification. I have changed the field names but still no luck.
 

Orthodox Dave

Home Developer
Local time
Today, 06:32
Joined
Apr 13, 2017
Messages
218
OK thanks to AccessBlaster's post, I now understand what you need. Sorry I was under the impression the user couldn't print the report. Ignore everything I've said up to now. (Understanding what the problem is, is often more difficult than solving it!)

1. If you don't already have it, you need a boolean (yes/no) field in the Data_Entry table and in the form's row source, to show if the report has been printed. You could call it fldPrinted

2. You should set the message box to come after the person has closed the report and ask msgBox("Did you successfully print the voucher?,vbYesNo). This is better than asking if the person wants to print the voucher, because they might not succeed because the printer has run out of paper etc. Code like this:-
Code:
if msgBox("Did you successfully print the voucher?,vbYesNo) = vbYes then
Me.fldPrinted = -1
End IF

3. Then at the beginning of the sub you could have something like:
Code:
Private Sub cmd_Print_Click()

if Me.fldPrinted = -1 then 
msgbox "Voucher has already been printed": exit sub 
end if  

    Dim strDocName As String ... etc etc

Not sure how your voucher system works, so if the voucher is allowed to be modified and re-printed, you need to allow for this in your code by re-setting fldPrinted to 0 if changes are made.
 

lookforsmt

Registered User.
Local time
Today, 09:32
Joined
Dec 26, 2011
Messages
672
Thank you Dave, below is the code i have applied in my project and it is exactly what i wanted. Only one observation on print command by default it selects all instead of current page. Although only one page gets printed.
I want to thank each and everyone who have given their time for helping me.

Code:
Private Sub cmd_Print_Click()

    If Me.fldPrinted = -1 Then
    MsgBox "Voucher has already been printed": Exit Sub
    End If

    Dim strDocName As String
    Dim strLinkCriteria As String
    
    strDocName = "rpt_Data_Entry"
    strLinkCriteria = "[SrId] = forms![frm_Data_Entry]![SrId]"
        
    DoCmd.RunCommand acCmdSaveRecord
    DoCmd.SelectObject acForm, frm_Data_Entry, True
    DoCmd.OpenReport strDocName, acViewPreview, , strLinkCriteria
        
    DoCmd.SelectObject acReport, strDocName
    DoCmd.RunCommand acCmdPrint
        
    If MsgBox("Did you successfully print the voucher?", vbYesNo) = vbYes Then
    Me.fldPrinted = -1
    
    End If
    
    DoCmd.Close
    
End Sub
 

Users who are viewing this thread

Top Bottom