Printing report from Navigation Subform (1 Viewer)

Flag

New member
Local time
Today, 07:13
Joined
Mar 7, 2017
Messages
8
Hi all. Have developed a few systems the 'old fashioned way' using command buttons. Have ignored navigation forms for too long. They are turning out to be a challenge! I have a db with top controls and linked side controls. All works well . . . until I try to print a report that is in the navigation subform. The report does not have the focus so I can't use On_Focus to send to the printer. Sometimes I just feel retarded ;). That's just a straight print and I haven't tried to send to the printer with a parameter query yet!!! Any help would be appreciated.
Cheers
Flag
The penny just dropped. I put the code on the side button. The problem with asking to filter the report between two dates still exits. I have no problem when not using navigation forms. They seem to handle things differently!
 
Last edited:

Ranman256

Well-known member
Local time
Today, 10:13
Joined
Apr 9, 2015
Messages
4,339
Make a form , frmReports, with the textboxes needed,
TxtDateStart,txtDateEnd.
Then make the query of the report read the form,

Select * from table where [myDate] between forms!frmReports!txtStartDate and forms!frmReports!txtStartEnd
 

sneuberg

AWF VIP
Local time
Today, 07:13
Joined
Oct 17, 2014
Messages
3,506
If the report is filtered via form references they need to be adjusted for now being in a Navigation Subform which as a default is named NavigationSubform. The main navigation form's default name is Navigation Form. Most people change the name of the main form but leave the subform named NavigationSubform. For this discussion I going to assume they both have the default names.

Lets say you have a form that named frmExample that has a textbox name txtStartDate on it. Outside of the NavigationSubform the full reference to it would be

Code:
[Forms]![frmExample]![txtStartDate]

Note that the brackets aren't really necessary in this case but reference are usually seen with them so I write them that way. Anyway if you move this form into the NavigationSubform the reference becomes.

Code:
[Forms]![Navigation Form]![NavigationSubform].[Form]![txtStartDate]

Some people are confused by the fact that the name frmExample has disappeared from this new reference. Perhaps more mysterious is that another form in another tab with a textbox name [txtStartDate] would have the same reference. The reason why this is is because there is only one form open at a time in the NavigationSubform. Access opens and closes forms as you switch from one tab to another.
 

Flag

New member
Local time
Today, 07:13
Joined
Mar 7, 2017
Messages
8
Thanks Ranman256. That is the method that I have used for years - outside navigation forms and it works well. However, it doesn't work for me within navigation forms. I think the problem is in the path referencing and sneuberg has pointed me in the right direction. I hope - will try it. Thanks for responding.
 

Flag

New member
Local time
Today, 07:13
Joined
Mar 7, 2017
Messages
8
Thanks sneuberg. Sounds good. Will give it a try and let you know.
Cheers
Flag
 

Flag

New member
Local time
Today, 07:13
Joined
Mar 7, 2017
Messages
8
This is what I had already used on a form to filter dates.

Between [Forms]![Home]![NavigationSubForm]![StartDate] And [Forms]![Home]![NavigationSubForm]![FinishDate]

It works well but I had to put the txt boxes in the header of the form with an update button to requery the form. Clunky but works. Again, outside Navigation forms I would show the search box first, allow user input, then put a continue button that closes the search box, reads the query then opens the form. I don't don't seem to be able to do this in Nav Forms!

In viewing reports I can't see any way of putting the search box on the report. So the above method will not work. In a nutshell what do I put on the print button to allow user input of dates then show the relevant report?

Your help is much appreciated.
 

sneuberg

AWF VIP
Local time
Today, 07:13
Joined
Oct 17, 2014
Messages
3,506
Sorry but I'm lost. Where do you want the print button and text boxes for the dates? On a form in the NavigationSubform or do you want to create a dialog form?

At the moment I can't think of anyway to put the search box on the report either. But if that's what you want to do I'll give it some thought. Let me know.
 

Flag

New member
Local time
Today, 07:13
Joined
Mar 7, 2017
Messages
8
I get lost all the time! ;-) Let's see if I can explain more clearly. At the moment I have a side button that opens a form (AttendForm). I put the 2 txt boxes in the header of this form (StartDate and FinishDate). Next to these I have a button that On_Click updates the form. Works a dream.

However, I can't work out how to do this date filter when I open a report!!! The method above will obviously not work as I can't put the txt boxes and button on the report.

So, I would like to click on the side button, ask for data input then print the resulting report. I hope I have clarified the situation a little sneuberg.
 

sneuberg

AWF VIP
Local time
Today, 07:13
Joined
Oct 17, 2014
Messages
3,506
I get lost all the time! ;-) Let's see if I can explain more clearly. At the moment I have a side button that opens a form (AttendForm). I put the 2 txt boxes in the header of this form (StartDate and FinishDate). Next to these I have a button that On_Click updates the form. Works a dream.

I'm guessing that you mean that when you click the button the records in the date range appear below in a continuous form.

However, I can't work out how to do this date filter when I open a report!!! The method above will obviously not work as I can't put the txt boxes and button on the report.

If I guessed right above and the records source of the report is, or can be made, the same as the form's records source then just put the print report button in the header of the form to open the report.
 

Flag

New member
Local time
Today, 07:13
Joined
Mar 7, 2017
Messages
8
What a champion you are. You were correct with your first guess. I was not intending to base the report on a form but gave it a go. Once again I put the request for user input in the form header along with an update form button and a print button. Both form and report were based on the same parameter query. Works like a charm. Thank you so much for your help.

The only problem now is that if the user cancels the print request I get a runtime error of 2501. Any advice on some error trapping please.
 

sneuberg

AWF VIP
Local time
Today, 07:13
Joined
Oct 17, 2014
Messages
3,506
This thread has this example which I believe it the typical way of handling this

Code:
Public Sub someSub
  'Need to add a statement to go to a label 
  On Error GoTo ErrHandler
      ' Your code here
     'Need to add exit so you do not enter the errhandler code
       Exit sub 
ErrHandler:
  If Err.Number = 2501 Then
    Resume Next
  Else
     MsgBox Err.Number & " " & Err.Description
  end if
end sub
 

Users who are viewing this thread

Top Bottom