Weird printing phenomena (1 Viewer)

irish634

Registered User.
Local time
Today, 10:04
Joined
Sep 22, 2008
Messages
230
I have a weird thing going on and I can't seem to pinpoint the cause.

I have Form1 used for data entry. I display the navigation buttons so I can cycle through records, etc.

I have Form2 with various command buttons to open various reports in print preview mode.

Keeping things to a simplistic description, the sequence of events are as follows:

  1. Open Form1 (show all records, but go to a new record for data entry).
  2. Enter data.
  3. Click a command button to open Form2. Prior to opening the form I save the new record.
  4. Click a command button on Form2 to open a report based on data.
Now here's the weird part. When I click print, to print the report ALL the records in Form1 are printed (like I am printing the form).

If I close the database and reopen it, I go to print, and the report prints fine.

Any thoughts?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:04
Joined
Oct 29, 2018
Messages
21,485
Hi Craig. What does the code for the Print button look like? Also, what does the code to open Form2 look like?
 

irish634

Registered User.
Local time
Today, 10:04
Joined
Sep 22, 2008
Messages
230
Code to open Form2:
Code:
Private Sub cmd_Reports_Click()
On Error GoTo Error_Handler

    If Me.Dirty = True Then                                     'If changes have been made to the record
        DoCmd.RunCommand acCmdSaveRecord                        'Save the record
    End If
    DoCmd.OpenForm "frm_Reports", acNormal
    
Error_Handler_Exit:
    Exit Sub
Error_Handler:
    Call ErrorLog(Err.Number, Err.Description, Me.Name, Me.ActiveControl.Name)
    Err.Clear
    Resume Error_Handler_Exit
    
End Sub
Then in Form2 to open the report:
Code:
On Error GoTo Error_Handler

    sDocName = "rpt_IChart"
    DoCmd.OpenReport sDocName, acViewPreview
    DoCmd.RunCommand acCmdFitToWindow
    
Error_Handler_Exit:
   Exit Sub

Error_Handler:
    If Err.Number = 2501 Then
        Err.Clear
        Resume Error_Handler_Exit
    Else
        Call ErrorLog(Err.Number, Err.Description, Me.Name, Me.ActiveControl.Name)
        Err.Clear
        Resume Error_Handler_Exit
    End If
    
End Sub
I don't have a button to print. I either use the print icon on the ribbon or select File--> Print


(Also, this is Access 2010 here at work. I have 2016 at home, but haven't checked that yet)
 
Last edited:

theDBguy

I’m here to help
Staff member
Local time
Today, 07:04
Joined
Oct 29, 2018
Messages
21,485
Hi Craig. Just a thought but try changing your code to this one:
Code:
DoCmd.OpenReport sDocName, acViewPreview, , "[ID]=" & Me.ID
Change [ID] to whatever is the name of your table's Primary Key field.
 

irish634

Registered User.
Local time
Today, 10:04
Joined
Sep 22, 2008
Messages
230
Form2 has no record source whatsoever. It is only used for buttons to open the various reports. There is no primary key to reference. So it won't even compile like that.

It's like the default print icon has no idea the report is open. Almost like the focus never leaves Form1, although form2 and the report are subsequently open.

Form1 has a record source for the underlying Table1.
Form2 has no record source, just command buttons to open reports.
IChart report has no record source, but the chart I display does. And that is based on Query1.

But printing after entering a new record, prints all the records in form1 when the report should be the focus.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:04
Joined
Oct 29, 2018
Messages
21,485
Form2 has no record source whatsoever. It is only used for buttons to open the various reports. There is no primary key to reference. So it won't even compile like that.

It's like the default print icon has no idea the report is open. Almost like the focus never leaves Form1, although form2 and the report are subsequently open.

Form1 has a record source for the underlying Table1.
Form2 has no record source, just command buttons to open reports.
IChart report has no record source, but the chart I display does. And that is based on Query1.

But printing after entering a new record, prints all the records in form1 when the report should be the focus.
Hi Craig. Are you able to post a sample copy of your db with test data?
 

irish634

Registered User.
Local time
Today, 10:04
Joined
Sep 22, 2008
Messages
230
It works as it should in Access 2016. Meaning I add data, click reports, open the report, and when I print it, the chart is printed like I want..

When in Access 2010 at work, it prints the records in the opening form as previously described.

On my long commute home, I began to wonder if it's because I have the form properties to modal and I am guessing Access 2010 and runtime has difficulty getting the focus to the right object. I'll test this theory tomorrow at work.


Here is a sample with everything else removed.
View attachment Cleanliness.accdb
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:04
Joined
Oct 29, 2018
Messages
21,485
It works as it should in Access 2016. Meaning I add data, click reports, open the report, and when I print it, the chart is printed like I want..

When in Access 2010 at work, it prints the records in the opening form as previously described.

On my long commute home, I began to wonder if it's because I have the form properties to modal and I am guessing Access 2010 and runtime has difficulty getting the focus to the right object. I'll test this theory tomorrow at work.


Here is a sample with everything else removed.
View attachment 75021
Hi Craig. The funny thing is, I am also using 2016, so I may not see the problem happen too. I'll let you know...
 

JHB

Have been here a while
Local time
Today, 16:04
Joined
Jun 17, 2012
Messages
7,732
..
When in Access 2010 at work, it prints the records in the opening form as previously described.
..
I've MS-Access 2010, could you give a description (include the data to input) step by step how to reproduce the error.
I've tried the attached database + inputting new data and then print the graph without problem.
 

irish634

Registered User.
Local time
Today, 10:04
Joined
Sep 22, 2008
Messages
230
I've MS-Access 2010, could you give a description (include the data to input) step by step how to reproduce the error.
I've tried the attached database + inputting new data and then print the graph without problem.


Exactly as you described.
Open the entry form...add data (what kind of data is irrelevant).

I click "Reports" then click the Run chart button, the chart displays. Then I use the print icon on the ribbon. That's it.


I'll work with it a little more today to test my theory above.
 

irish634

Registered User.
Local time
Today, 10:04
Joined
Sep 22, 2008
Messages
230
Ok... after a while of trial and error I think I have it narrowed down.

It has something to do with the attachment field.
This field is usually the last thing I populate before printing a chart.

When I add or remove a file from the field, and then immediately go to the report form to print the report, I get all the records from the first form and not the chart.

It seems to only do it when initially opening the form and immediately adding data. I have not been able to duplicate when editing a record.

If I don't do anything with the attachment field, it prints normally.

So far I have tried setting the focus to another control and it still does it.

Last night when I was working in 2016, I did not do anything with the attachment field.


So I am now trying to figure out how to stop it.
 
Last edited:

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 09:04
Joined
Feb 28, 2001
Messages
27,209
You say the form has no controls other than command buttons. By any chance did you make all of the command buttons with property .TabStop = No?

The reason I asked is because if you have NO controls on the form with tab stop = Yes then it is one of the rare cases that focus can actually be on the form rather than a control. Your statement about it seeming that control doesn't pass to the sub-form makes me wonder if, for a sub-form with no resident tab stops, you cannot pass control there at all. I do not know this to be true, and if anything on the form HAS TabStop=Yes then it doesn't matter anyway. Consider this a "random" thought that might be appropriate but also might not.
 
Last edited:

irish634

Registered User.
Local time
Today, 10:04
Joined
Sep 22, 2008
Messages
230
You say the form has no controls other than command buttons. By any chance did you make all of the command buttons with property .TabStop = No?

To answer your question, No. I only set tab stop to no when I hide a control.
It's not really a subform. I actually open a new form, and then a report. So the main form in question is twice removed from the top object (my report).

As mentioned, is only seems to happen when the attachment field is the last thing used when the form is first used. It seems irrelevant when cycling to a random record and editing it. If I don't use the attachment field last, it works fine.

But, to try to remove the focus from the attachment field, I did set the focus to another control and still got the same result.
 
Last edited:

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 09:04
Joined
Feb 28, 2001
Messages
27,209
No, it wouldn't change anything if you had at least one item with .TabStop=Yes on that form. But re-reading this sequence a second time, I see I misinterpreted Form2.

So you say the problem is that you open the form, create a new record, and try to attach something (perhaps a graph) and then try to print a report that contains one record and an attached chart - but you get more than one record and no attached chart. Is that the summary of the problem?
 

irish634

Registered User.
Local time
Today, 10:04
Joined
Sep 22, 2008
Messages
230
So you say the problem is that you open the form, create a new record, and try to attach something (perhaps a graph) and then try to print a report that contains one record and an attached chart - but you get more than one record and no attached chart. Is that the summary of the problem?

Kind of. There is a sample DB in a previous post. These objects are part of a larger DB but the same issue appears in this standalone.

The process is as follows:

  1. Open the DB
  2. Open the first form (frm_CleanlinessTestData) When the form opens, I automatically go to a new record. This form is bound to the underlying data table.
  3. Add data. The test report from the machine is attached as my last step on this form. Its a small PDF. I attach the report then go to the next step
  4. After I add the data, I click the "Reports" command button to open another form (frm_CleanlinessTestReports) that has numerous command buttons to open various reports. In the on click event of this Reports command button, I save the record so all the data will be displayed in my chart.
  5. Once in the second form (this form is unbound and only displays command buttons), I click the command button for the report I want to run. In the sample provided, it's the run chart.
  6. When I click the report button, the report opens as it should. So now there are 3 objects open. (The report is unbound, but the chart in it is bound to a query).
  7. I use the print icon on the default ribbon, or click file print.
Following the steps above will print all the records in the form first opened (just like if the form was active and I clicked print while in the form), instead of the report. Every time. Then the print button usually greys out.

If I close the DB and reopen it, go directly to the report, it prints the report as it should.

Now some caveats....

  • It seems if I cycle to a record, remove the attachment, and try to print the report the same thing happens. If I do this and change another control, the problem happens.
  • If I add a record, but add the attachment first, then add the data, then try to print the report it prints the report.
  • If I open the DB, add data, and do not add an attachment, the report prints fine.
  • If I open the DB, edit a record without touching the attachment field, the report prints fine.

It really seems centered around the attachment field.

I have tried (all in the on click event of the "Reports" command button) in an attempt to get off the attachment control:

  • Setting the focus to another field before opening second form;
  • Cycling to another record, then back to the record just entered.
  • Adding a new record
None of this has worked to correct it so far. I'm still dabbling.
It's one of the craziest things I have seen.
 
Last edited:

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 09:04
Joined
Feb 28, 2001
Messages
27,209
At this point I have no understanding of the mechanism that leads to this point. I will try to wrap my head around it but cannot make promises.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:04
Joined
Oct 29, 2018
Messages
21,485
...
It really seems centered around the attachment field.

I have tried (all in the on click event of the "Reports" command button) in an attempt to get off the attachment control:

  • Setting the focus to another field before opening second form;
  • Cycling to another record, then back to the record just entered.
  • Adding a new record
None of this has worked to correct it so far. I'm still dabbling.
It's one of the craziest things I have seen.
Hi Craig. Just curious, do you know if this behavior has been there all along, and you just only recently noticed it. Or, do you think it was working fine before and just suddenly started acting this way now?
 

irish634

Registered User.
Local time
Today, 10:04
Joined
Sep 22, 2008
Messages
230
Hi Craig. Just curious, do you know if this behavior has been there all along, and you just only recently noticed it. Or, do you think it was working fine before and just suddenly started acting this way now?


This is a new portion of the larger database. The objects for this testing (forms, queries, tables, reports) are about 2 months old. This is the only table where I actually use the attachment field so I cannot answer your question other than to say, I think it has been there all along.
 

irish634

Registered User.
Local time
Today, 10:04
Joined
Sep 22, 2008
Messages
230
Things Tried (in On_Click Event of Reports Button): These do not correct the issue
-Set focus to another control
-Go to another record then back to prev
-Form Refresh
-Add new record
-Form Requery

Things found to stop the issue from happening:
-Close first form then re-open it, run the reports
-Show a message box before opening the 2nd form
-Set the 2nd form to popup = Yes (close after opening report)


I'm still trying to find a way to correct this less intrusively (no popups)
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:04
Joined
Oct 29, 2018
Messages
21,485
Things Tried (in On_Click Event of Reports Button): These do not correct the issue
-Set focus to another control
-Go to another record then back to prev
-Form Refresh
-Add new record
-Form Requery

Things found to stop the issue from happening:
-Close first form then re-open it, run the reports
-Show a message box before opening the 2nd form
-Set the 2nd form to popup = Yes (close after opening report)


I'm still trying to find a way to correct this less intrusively (no popups)
Hi Craig. Thanks for the update. When I get a chance, I am planning on creating a similar setup from scratch just to see if this is standard behavior or if your file somehow got corrupted.
 

Users who are viewing this thread

Top Bottom