docmd.SelectObject - .PrintAll problem (1 Viewer)

TorsteinKrogh

New member
Local time
Today, 06:17
Joined
Oct 17, 2017
Messages
7
Hi, For years I had this code running looping thru a list of orders printing 4 reports from each order using the .SelectObject and PrintAll. After my customer got a new Windows server, it prints the open form 4 times instead of the reports. I have tried Access 2013 and 2016 on two different printers and the Microsoft printer, it is all the same!!
Microsoft Prof Support wont help.
 

JHB

Have been here a while
Local time
Today, 06:17
Joined
Jun 17, 2012
Messages
7,732
Where do you've that code, (show your code)?
 

TorsteinKrogh

New member
Local time
Today, 06:17
Joined
Oct 17, 2017
Messages
7
:banghead: the code is in a small pdf over this 100kb limit. how do I upload it?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 12:17
Joined
May 7, 2009
Messages
19,228
what was meant was paste your vba code here.
 

TorsteinKrogh

New member
Local time
Today, 06:17
Joined
Oct 17, 2017
Messages
7
Hi, here comes the code in Excel:)
 

Attachments

  • BAS fakturere mange.xlsx
    106.6 KB · Views: 111

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 12:17
Joined
May 7, 2009
Messages
19,228
Yes i saw it. You must enclosed your report Name in double quote.

Eg:

DoCmd.SelectObject acReport, "Rptl", True
 

TorsteinKrogh

New member
Local time
Today, 06:17
Joined
Oct 17, 2017
Messages
7
Private Sub skrFakt_Click()
Dim rst As DAO.Recordset
Dim AntPoster As Integer
Dim i As Integer
Dim Rptl As String, Rpt2 As String, BetDok As String Dim Timeliste_regning As String
'sjekk at det ikke er brukt flere satser for samme art
If DCount("*" "OrdrerTilFakt_sjekkArt") > O Then
MsgBox "Du har brukt forskjellige satser for samme art" & vbCrLf &

"Rett opp ved å kjøre 'Timepriser, endre for ordre' etter feillista '
DoCmd.OpenQuery "OrdrerTilFakt sjekkArt", acViewNormal, acReadOnly
GoTo ut
End If
DoCmd.SetWarnings False
DoCmd.OpenQuery "Pos MVA fixJAI', acViewNormal, acEdit
DoCmd.OpenQuery "Pos MVA fixNEl", acViewNormal, acEdit
DoCmd.SetWarnings True
Set rst = Me.RecordsetClone
' rst.Open "Ordrer_til_fakturering", CurrentProject.AccessConnection rst.MoveFirst
Rptl = "Faktura er"
Rpt2 -- "Matr RA fleir"
BetDok = "Bankgiro_er" Timeliste_regning = "Timer_fakt_regn"
AntPoster = DCount(
' AntPoster = 1
If AntPoster = O Then GoTo ut
For i = 1 To AntPoster Me.Bookmark = rst.Bookmark
Summere påløpt
DoCmd.SetWarnings False
DoCmd.OpenQuery "PosBruktMT OTF", acViewNormal, acEdit
DoCmd.OpenQuery "PosBrukt_OTF", acViewNormal, acEdit
DoCmd.SetWarnings True
Faktura
DoCmd.SelectObject acReport, Rptl, True
DoCmd.PrintOut acPrintAll
' Materialliste
DoCmd.SelectObject acReport, Rpt2, True
DoCmd.PrintOut acPrintAll
' Timeliste
DoCmd.SelectObject acReport, Timeliste_regning, True
DoCmd.PrintOut acPrintAll
Beta lingsdokument
DoCmd.SelectObject acReport, BetDok, True
DoCmd.PrintOut acPrintAll
rst.MoveNext
Next i
rst.Close Set rst = Nothing
Set db = Nothing
ut: End Sub
 

jdraw

Super Moderator
Staff member
Local time
Today, 00:17
Joined
Jan 23, 2006
Messages
15,379
This line
If DCount("*" "OrdrerTilFakt_sjekkArt") > O Then

seems to be missing a separator (comma) after "*" and the O looks like alpha O as compared to zero 0.
 

TorsteinKrogh

New member
Local time
Today, 06:17
Joined
Oct 17, 2017
Messages
7
Thanks, but that is a transfer error, it would not have compiled with such an syntax error. The issue is: Why does the selectObject ignore the Repor parameter and printes the active form instead??
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 12:17
Joined
May 7, 2009
Messages
19,228
I think that has changed in a2013/2016.

Instead of using SelectObject, you can try OpenReport with its View parameter as acHidden. After do the printout. Then after close the report.

Do this with the rest of reports.
 

jdraw

Super Moderator
Staff member
Local time
Today, 00:17
Joined
Jan 23, 2006
Messages
15,379
Thanks, but that is a transfer error, it would not have compiled with such an syntax error. The issue is: Why does the selectObject ignore the Repor parameter and printes the active form instead??

Yes I agree, it should not compile. For anyone looking at the code detail--
The missing separator could be a transfer error, but the "O" is ascii 79 which is a capital O --not zero. May not be related to your problem, but with the DCount you want a numeric 0, not an alpha O.
 

JHB

Have been here a while
Local time
Today, 06:17
Joined
Jun 17, 2012
Messages
7,732
I don't have Access 2013 and 2016 so I can't test the DoCmd.SelectObject, but if you can't use the OpenReport suggested from arnelgp, I could create a new form with a button on it and the below code behind it.
Then you can test and see if that printout correct.
Code:
DoCmd.SelectObject acReport, "Faktura er", True
DoCmd.PrintOut acPrintAll
Only a question, do you have anywhere in our code "On Error Resume Next"?
 

TorsteinKrogh

New member
Local time
Today, 06:17
Joined
Oct 17, 2017
Messages
7
ARNELGP: YOU ARE A GENIUS! I tested this replacement code:

docmd.openreport Rpt1,,,,acHidden
Docmd.Close acreport,Rpt1

and it works! I am so happy.
Microsoft Support Professional Support gave up but you knew the answer. Thanks again!
 

Users who are viewing this thread

Top Bottom