Solved MS Access VBA DoCmd Print Command Error (1 Viewer)

nectorch

Member
Local time
Today, 08:10
Joined
Aug 4, 2021
Messages
41
Dear Experts!

Sorry once again!

I want to have a POS receipt sent directly to the printer after selecting the receipt number in the combo box using the after events property, but it is giving me an error. I do not want to preview anything here , below is my VBA Code.

Code:
Private Sub CbotemporalSigningCombo_AfterUpdate()
On Error GoTo 0
Me.txtPrintPOSKitwe = Me.CbotemporalSigningCombo.Column(0)
Dim db As DAO.Database
Dim strSQL As String
Set db = CurrentDb
strSQL = "SELECT [tblPOSStocksSold].[ItemSoldID] FROM [QryTemporalSigningPOS] WHERE [tblPOSStocksSold].[ItemSoldID] = " & Me.CbotemporalSigningCombo
DoCmd.SetWarnings False
DoCmd.OpenQuery "QryTemporalSigningPOS"
db.Close
Set db = Nothing
MsgBox "Your invoice has been signed and now being printed", vbInformation, "Please Proceed"
On Error GoTo 0
DoCmd.OpenReport "RptPosReceipts", acViewPreview, "", "", acNormal
DoCmd.RunCommand acCmdPrint
DoCmd.Close acReport, "RptPosReceipts"
Me.CbotemporalSigningCombo = ""
Me.CbotemporalSigningCombo.Requery
Me.FCRate = 1
Me.CurrencyType = "ZMW"
Me.PosDate = Date
Me.Cashier = Forms!frmLogin!txtpersoning.value
Me.CartID = 3
Me.SalesTypes = 0
Me.PaymentMode = 0
Me.TransactionType = 0
Me.AllocationDate = Date
Me.WHID = Forms!frmLogin!txtBranchOne.value
Me.sfrmPosLineDetails_Subform.SetFocus
On Error GoTo 0
End Sub

(2) since after printing the header form is completed automatically, now suppose the change his/her mind, can the transaction be canceled without creating a new blank transaction.
 

Minty

AWF VIP
Local time
Today, 07:10
Joined
Jul 26, 2013
Messages
10,371
What is the error and what line doe it occur on?
 

nectorch

Member
Local time
Today, 08:10
Joined
Aug 4, 2021
Messages
41
The error is occurring immediately after preview which is visible to everyone ,the error is wrong property assignment. Here I do not want to see the preview mode but direct printing
 

ebs17

Well-known member
Local time
Today, 08:10
Joined
Feb 7, 2020
Messages
1,946
I do not want to preview anything here
DoCmd.OpenReport "RptPosReceipts", acViewPreview acViewNormal, "tblPOSStocksSold.ItemSoldID = " & Me.CbotemporalSigningCombo"

There's a lot of nonsense and unstructured stuff in your code.
 

nectorch

Member
Local time
Today, 08:10
Joined
Aug 4, 2021
Messages
41
Fortunately the code below has worked as required:

Code:
DoCmd.OpenReport "RptPosReceipts", acViewPreview, "", "", acNormal
DoCmd.PrintOut
DoCmd.Close acReport, "RptPosReceipts"
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 02:10
Joined
Feb 19, 2002
Messages
43,275
@ebs17 told you how to resolve the problem. Why would you ignore the advice and not just use the very simple????
DoCmd.OpenReport "RptPosReceipts", acViewNormal
 

nector

Member
Local time
Today, 09:10
Joined
Jan 21, 2020
Messages
368
Kindly tone it down, I have used that code but unfortunately besides printing the actual receipt it also printing the data capturing form which is not needed at all, I do not need the parent form and subform to be printed.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 02:10
Joined
Feb 19, 2002
Messages
43,275
We may be having a language issue. I don't care if you want to use three lines of code because you are using the wrong argument in the print command rather than using a single line with the correct argument which won't even open the report visibly at all.
I want to have a POS receipt sent directly to the printer after
You were given the SINGLE line of code that does this. It is accomplished by using the correct argument in the print command. I was trying to make you understand the inefficiency of the alternate method which requires that the report be opened in print preview which you specifically said you did not want to do.
 

nector

Member
Local time
Today, 09:10
Joined
Jan 21, 2020
Messages
368
My apology Pat Hartman you were right I completely misunderstood you because the code was not making sense on my side because I was looking for the word "Print" which was completely inappropriate.

Actually the code below send the report directly to the printer which is what I wanted.

Code:
Docmd.openreport "reportName", acViewNormal

The other parts are not required at all.

Code:
DoCmd.PrintOut
DoCmd.Close acReport, "RptPosReceipts"

Many thank to sir & Ebs17. I'm now happy the POS is working faster
 

Users who are viewing this thread

Top Bottom