amberdextrous
MIS
Hello. I'm new to Access and VBA. I'm developing a database for my company and I've basically been teaching myself as I go along, and I've been using A LOT of code help from forums. We have a cabinet full of CDs with archived project files on them and if you need to look at an old project for whatever reason, there's no way to see what's on each disc, which needless to say causes a lot of headaches. So I'm making a database that stores project data and disc data, so that you can do a search by project #, client #, etc. and the database will pull up the names of the disc(s) the data is stored on.
That being said, I have a form that displays all records and when you click the Search button, a popup form displays so the user can search by various criteria...once the search executes, the popup closes and the data on the first form is filtered to show the data matching the user's criteria.
There is also a "Generate Report" button that when clicked, generates a report of only the records matching the criteria. Here's my problem: I want it to perform so that when clicked, the report is automatically generated based on the Search Results. As it stands, when it is clicked, Access prompts for criteria, which means the user has to re-input their criteria. The report works when you do this, but it is redundant for the user. I want the data to pass to the report without further input.
Here is the SQL for my query used to search the records. The report is also based off this query, which is probably what's causing my problem:
SELECT Client.[Client ID], Project.[Project ID], Disc.[Disc ID], Client.[Client Description], Project.[Project Description], Project.[Project Manager]
FROM Client, Project, Disc, [Project On Disc]
WHERE Client.[Client ID]=Project.[Client ID] And Project.[Project ID]=[Project On Disc].[Project ID] And [Project On Disc].[Disc ID]=Disc.[Disc ID] And Client.[Client ID] Like "*" & Forms!SearchForm!EnterClientNumber & "*" And Client.[Client Description] Like "*" & Forms!SearchForm!EnterClientName & "*" And Project.[Project ID] Like "*" & Forms!SearchForm!EnterProjectNumber & "*" And Project.[Project Description] Like "*" & Forms!SearchForm!EnterProjectDescrip & "*" And Project.[Project Manager] Like "*" & Forms!SearchForm!EnterProjectManager & "*" And Disc.[Disc ID] Like "*" & Forms!SearchForm!EnterDiscID & "*"
ORDER BY Client.[Client ID], Project.[Project ID], Disc.[Disc ID];
This is the code for "View all" and "Generate report" on the main form where the records are displayed:
--------------
Private Sub ShowAllButton_Click()
Dim LSQL As String
'Display all customers
LSQL = "SELECT Client.[Client ID], Project.[Project ID], Disc.[Disc ID], Client.[Client Description], Project.[Project Description], Project.[Project Manager] FROM (Client INNER JOIN Project ON Client.[Client ID]=Project.[Client ID]) INNER JOIN (Disc INNER JOIN [Project On Disc] ON Disc.[Disc ID]=[Project On Disc].[Disc ID]) ON Project.[Project ID]=[Project On Disc].[Project ID]"
Form_ViewDataForm.RecordSource = LSQL
Form_ViewDataForm.Caption = "View all records"
MsgBox ("All records are now displayed.")
End Sub
Private Sub GenerateReportButton_Click()
On Error GoTo Err_GenerateReportButton_Click
Dim stDocName As String
stDocName = "rptSearchResults"
DoCmd.OpenReport stDocName, acPreview
Exit_GenerateReportButton_Click:
Exit Sub
Err_GenerateReportButton_Click:
MsgBox Err.Description
Resume Exit_GenerateReportButton_Click
End Sub
--------------
This code is on my Search popup form:
--------------
Private Sub SearchButton_Click()
'Filter data based on search criteria
Form_ViewDataForm.RecordSource = "SearchQuery2"
Form_ViewDataForm.Caption = "Search Results"
'Close Search Form
DoCmd.Close acForm, "SearchForm"
MsgBox "Results have been filtered."
End Sub
--------------
If anyone knows how I can get the main form to pass the query results to the report without having Access prompt for the criteria again, I would REALLY appreciate the help!!
That being said, I have a form that displays all records and when you click the Search button, a popup form displays so the user can search by various criteria...once the search executes, the popup closes and the data on the first form is filtered to show the data matching the user's criteria.
There is also a "Generate Report" button that when clicked, generates a report of only the records matching the criteria. Here's my problem: I want it to perform so that when clicked, the report is automatically generated based on the Search Results. As it stands, when it is clicked, Access prompts for criteria, which means the user has to re-input their criteria. The report works when you do this, but it is redundant for the user. I want the data to pass to the report without further input.
Here is the SQL for my query used to search the records. The report is also based off this query, which is probably what's causing my problem:
SELECT Client.[Client ID], Project.[Project ID], Disc.[Disc ID], Client.[Client Description], Project.[Project Description], Project.[Project Manager]
FROM Client, Project, Disc, [Project On Disc]
WHERE Client.[Client ID]=Project.[Client ID] And Project.[Project ID]=[Project On Disc].[Project ID] And [Project On Disc].[Disc ID]=Disc.[Disc ID] And Client.[Client ID] Like "*" & Forms!SearchForm!EnterClientNumber & "*" And Client.[Client Description] Like "*" & Forms!SearchForm!EnterClientName & "*" And Project.[Project ID] Like "*" & Forms!SearchForm!EnterProjectNumber & "*" And Project.[Project Description] Like "*" & Forms!SearchForm!EnterProjectDescrip & "*" And Project.[Project Manager] Like "*" & Forms!SearchForm!EnterProjectManager & "*" And Disc.[Disc ID] Like "*" & Forms!SearchForm!EnterDiscID & "*"
ORDER BY Client.[Client ID], Project.[Project ID], Disc.[Disc ID];
This is the code for "View all" and "Generate report" on the main form where the records are displayed:
--------------
Private Sub ShowAllButton_Click()
Dim LSQL As String
'Display all customers
LSQL = "SELECT Client.[Client ID], Project.[Project ID], Disc.[Disc ID], Client.[Client Description], Project.[Project Description], Project.[Project Manager] FROM (Client INNER JOIN Project ON Client.[Client ID]=Project.[Client ID]) INNER JOIN (Disc INNER JOIN [Project On Disc] ON Disc.[Disc ID]=[Project On Disc].[Disc ID]) ON Project.[Project ID]=[Project On Disc].[Project ID]"
Form_ViewDataForm.RecordSource = LSQL
Form_ViewDataForm.Caption = "View all records"
MsgBox ("All records are now displayed.")
End Sub
Private Sub GenerateReportButton_Click()
On Error GoTo Err_GenerateReportButton_Click
Dim stDocName As String
stDocName = "rptSearchResults"
DoCmd.OpenReport stDocName, acPreview
Exit_GenerateReportButton_Click:
Exit Sub
Err_GenerateReportButton_Click:
MsgBox Err.Description
Resume Exit_GenerateReportButton_Click
End Sub
--------------
This code is on my Search popup form:
--------------
Private Sub SearchButton_Click()
'Filter data based on search criteria
Form_ViewDataForm.RecordSource = "SearchQuery2"
Form_ViewDataForm.Caption = "Search Results"
'Close Search Form
DoCmd.Close acForm, "SearchForm"
MsgBox "Results have been filtered."
End Sub
--------------
If anyone knows how I can get the main form to pass the query results to the report without having Access prompt for the criteria again, I would REALLY appreciate the help!!