As you are going to opening this main form through VBA code and we have to have a way to prompt for the beginning and ending dates, copy and paste the following code into a database module:
Global vStartDate as Date
Global vEndDate as Date
Function StartDate() as Date
StartDate = vStartDate
End Function
Function EndDate() as Date
EndDate = vEndDate
End Function
The SQL for the subform query should look something like this:
SELECT A.*
FROM Projects as A
WHERE (A.ContractStartDate >= BeginDate() and A.ContractStartDate <= EndDate) and (A.ContractExpireDate >= BeginDate());
This logic here assumes that you want to show all projects that any of the days of the contract falling within the promped BeginDate and EndDate. If a Project starts before the date range but ends after the beginning of the date range then it is included. Also, if a project starts anywhere within the date range then it is included. Projects that start after the end of the date range are excluded.
Now using this same query logic we should use the following SQL to select the records for the Main Form:
SELECT A.CustomerID, A.Field1, A.Field2, A.Field3, A.Field4, . . .(listing all fields needed)
FROM Customer as A INNER JOIN Project as B ON A.CustomerID = B.CustomerID
WHERE (B.ContractStartDate >= BeginDate() and B.ContractStartDate <= EndDate) and (B.ContractExpireDate >= BeginDate())
GROUP BY A.CustomerID, A.Field1, A.Field2, A.Field3, A.Field4, . . .(listing all fields listed above in the select);
Now using this above SQL for a query, this query should be the RecordSource for the Main Menu. This will set this form up as a bound form rather than unbound as you had it setup before.
Finally, we need to prompt for the date range and open the form. Put the following VBA code behind a button on the form that is making the call to open this form:
Private Sub CommandButton_Click()
On Error GoTo Err_CommandButton_Click
DoCmd.SetWarnings False
StartOver:
vStartDate = DateValue(InputBox("Enter Starting Date(i.e. mm/dd/yyyy): "

)
vEndDate = DateValue(InputBox("Enter Ending Date(i.e. mm/dd/yyyy): "

)
DoCmd.OpenForm "frmYour_Main_FormName"
DoCmd.SetWarnings True
Exit_CommandButton_Click:
Exit Sub
Err_CommandButton_Click:
If err = 13 then
MsgBox "The Date must be entered in the format mm/dd/yyyy. & vbCrLf & vbCrLf & "Try Again."
GoTo StartOver
Else
Resume Exit_CommandButton_Click
End If
End Sub
This code will prompt for the two dates and require that they be entered in "mm/dd/yyyy" format. If an error occurs in the entry a message will popup and force the user to start over.
Post back if you have any questions here. I have thrown a lot out here for you to digest so it may be a bit confusing and I may have made a typo or left something out. Just let me know.
Bob Scriver
Want the best answers? See FAQ181-2886
Nobody believes the official spokesman... but everybody trusts an unidentified source.
Author, Bagdad Bob???