This is my first post, and I'm brand new to developing MS Access databases, so please bear with me.
I built a database in MS Access 2010 (attached via zip file) with three tables: Clients (primary key: Client Code, which is a Text datatype), Contacts (primary key: Contact Name, which is a Text datatype) and Jobs (primary key: Job Number, which is an AutoNumber datatype). The Clients table has a 1-to-Many relationship with both Contacts and Jobs. The Contacts table has a 1-to-Many relationship with Jobs.
To enter new information, I have a Clients Form with a Jobs Subform. I didn't create a subform for Contacts, but instead dragged the Contacts table itself into the Clients Form. Within the Clients Form, I have a command button to Print Job Report. The command button's Record Source is a Query with information from all 3 tables. Here is the On Click code I have set up:
Private Sub cmdPrintJob_Click()
Dim strReportName As String
Dim strCriteria As String
strReportName = "Job Report"
strCriteria = "[Client Code]='" & Me![Client Code] & "'"
DoCmd.OpenReport strReportName, acViewPreview, , strCriteria
End Sub
I'd like to print a report of the current Job Number that I'm viewing. Using only the above code, my report was displaying all jobs assigned to that client. So I added =[Forms]![CTG - Jobs subform]![Job Number] to the Criteria line of my query. After doing this, I began receiving prompts to enter a Parameter value whenever I run the query and whenever I click the "Print Job Report" command button in the Clients Form. I actually receive the parameter prompt 3 times when click the command button. I believe this is because I'm separating information on my report by the 3 separate tables..
When I enter the parameter 3 times, the report runs properly. My goal is to produce the report without having to enter the parameter.
I may be way off base here, but should I use the tables as the record source of my report instead of the query? If so, what is the proper VBA code to print the current Job Number that I'm viewing?
I appreciate any assistance you can offer me!
Ryan
I built a database in MS Access 2010 (attached via zip file) with three tables: Clients (primary key: Client Code, which is a Text datatype), Contacts (primary key: Contact Name, which is a Text datatype) and Jobs (primary key: Job Number, which is an AutoNumber datatype). The Clients table has a 1-to-Many relationship with both Contacts and Jobs. The Contacts table has a 1-to-Many relationship with Jobs.
To enter new information, I have a Clients Form with a Jobs Subform. I didn't create a subform for Contacts, but instead dragged the Contacts table itself into the Clients Form. Within the Clients Form, I have a command button to Print Job Report. The command button's Record Source is a Query with information from all 3 tables. Here is the On Click code I have set up:
Private Sub cmdPrintJob_Click()
Dim strReportName As String
Dim strCriteria As String
strReportName = "Job Report"
strCriteria = "[Client Code]='" & Me![Client Code] & "'"
DoCmd.OpenReport strReportName, acViewPreview, , strCriteria
End Sub
I'd like to print a report of the current Job Number that I'm viewing. Using only the above code, my report was displaying all jobs assigned to that client. So I added =[Forms]![CTG - Jobs subform]![Job Number] to the Criteria line of my query. After doing this, I began receiving prompts to enter a Parameter value whenever I run the query and whenever I click the "Print Job Report" command button in the Clients Form. I actually receive the parameter prompt 3 times when click the command button. I believe this is because I'm separating information on my report by the 3 separate tables..
When I enter the parameter 3 times, the report runs properly. My goal is to produce the report without having to enter the parameter.
I may be way off base here, but should I use the tables as the record source of my report instead of the query? If so, what is the proper VBA code to print the current Job Number that I'm viewing?
I appreciate any assistance you can offer me!
Ryan