Recently, a question was posted in the community about requiring users to enter a password before reprinting the sales document. I thought I ‘ll document in detail for future references. Steps for accomplishing this are
Select TIMESPRT from SOP10100 where SOPNUMBE=’XXX’
Select TIMESPRT from IVC10100 where INVCNMBR=’xxx’
Select DocPrinted from RM10301 where DOCNUMBR=’XXX’
I am using the Sales Transaction entry window in the example below. Similar prompt can be easily added in the Invoice Entry or Transaction Entry window
Code for checking if invoice was already printed
Option Explicit
Dim cn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim cmd As New ADODB.Command
Dim sqlstring As String
Private Sub WindowPrint_BeforeUserChanged(KeepFocus As Boolean, CancelLogic As Boolean)
Dim timesPrinted As Integer
Set cn = UserInfoGet.CreateADOConnection
‘Use a client-side cursor so that a recordset count can be obtained later.
cn.CursorLocation = 3
‘set the database to the currently logged in db
cn.DefaultDatabase = UserInfoGet.IntercompanyID
sqlstring = “Select TIMESPRT from SOP10100 where SOPNUMBE=’” & RTrim(DocumentNo.Value) & “‘”
‘ ADO Command
cmd.ActiveConnection = cn
‘ adCmdText
cmd.CommandType = 1
‘ Command
cmd.CommandText = sqlstring
Set rst = cmd.Execute
If Not (rst.EOF And rst.BOF) Then
timesPrinted = RTrim(rst!TIMESPRT)
End If
rst.Close
‘ Close ADO Connection
If rst.State = adStateOpen Then rst.Close
If cn.State = adStateOpen Then cn.Close
Set cn = Nothing
Set rst = Nothing
Set cmd = Nothing
‘If already printed, display password prompt
If timesPrinted > 0 Then
Dim enterPass As New EnterPassword
enterPass.Show vbModal
If Not enterPass.isAuthorised Then
CancelLogic = True
MsgBox “You are not authorised to re print the invoice”
End If
End If
End Sub
Code behind of the custom form EnterPassword
Public isAuthorised As Boolean
Private Sub btnCancel_Click()
isAuthorised = False
Unload Me
End Sub
Private Sub btnOK_Click()
If txtPassword.Value = “XXXXXX” Then ‘Save password in secure location
isAuthorised = True
Else
isAuthorised = False
End If
Unload Me
End Sub
Code to enable/disable checkbox on “Reprint Previously Printed/Sent” in Print Sales Documents window (Transactions >> Sales >> Print Sales Documents)
Option Explicit
Private Sub Documents_BeforeGotFocus(CancelLogic As Boolean)
Documents.Enabled = False
Dim enterPass As New EnterPassword
enterPass.Show vbModal
If Not enterPass.isAuthorised Then
CancelLogic = True
MsgBox “You are not authorised to re-print the invoice”
Documents.Enabled = False
Else
Documents.Enabled = True
End If
End Sub
Downloads: