I have a single Access report which is based on a query and I am trying to add a parameter for one of the fields (Dept) so that the user can run the report for the one Dept they specify rather than all depts.
I have created a form with a combo box which lists the options they can choose from and I have linked this form and control to the query in the report ‘[Forms]![InputDept]![Combo14]’. I have two buttons on the form: one I have called ‘Ok’ and one I have called ‘Cancel’. For both buttons the event ‘On click’ is linked to a macro.
‘OK’ macro hides the form when the user clicks the Ok button.
‘Cancel’ macro closes the form when the user clicks the Cancel button.
When I run the report the form opens and the report correctly filters for the dept which has been selected in the parameter form. The problem I have is when I go to print preview the form....the parameter form opens again. And it also opens when I close print preview. Is this because I have just hidden the form? It doesn't appear to be 'active' because if i change the dept that is selected the print preview page is displayed showing the dept originally selected when the report was run.
In the events tab in the properties section of the form I have a macro ‘Open Dialog’ on the ‘On Open’ event which opens the parameter form.
I have attached the Open Dialog and OK macros.
Attachment 5991
Attachment 5992
I’m not that familiar with Visual Basic and this is the first time I have used a parameter form with a report.
Any help would be appreciated.
Thanks in advance