-----Original Message-----
OK ... let's clear the terminology first otherwise it is very confusing:
* A Form (whether it is being used as a normal Form or a Subform) does NOT
have Fields. Form only have *Controls*. These Controls may be bound to the
Fields of the RecordSource (Table or Query) of the Forms.
* Only Tables or Queries have Fields or Columns.
Let's confirm what you have done:
* On your (main) Form "frmMain" (substitute with the Name of your main
Form), you have 2 TextBox Controls name [txtStartDate] and [txtEndDate].
* On this Form, you have a CommandButton Control named [Command39]. Much
better to use a meaningful name but leave it aside for the moment.
* You have a Form by the name [Query5Subform] which is being used as the
SourceObject for the Subform Control also by the name [Query5Subform].
* When the frmMain is opened, the SourceObject of the SubformControl is NOT
set.
Please do the following:
* Rename the *SubformControl* to [sfrQuery5] to make it different from the
Form name of the SourceObject. FYI: "sfr" is the prefix used for the
SubformControl and "fsf" is the prefix for the Form being used as the
SourceObject of a SubformControl.
* In the DesignView of your Query, change the criteria to:
BETWEEN [Forms]![frmMain]![txtStartDate]
AND [Forms]![frmMain]![txtEndDate]
(remember to change [frmMain])
* Still in DesignView of the Query, use the Menu Query / Parameters ... and
declare the 2 references used in the criteria above as of DateTime type.
Save & close the Query.
* Change your Procedure to:
Private Sub Command39_Click()
Me.sfrQuery5.SourceObject = "Query5Subform"
End Sub
* Now open your Form, fill in the dates and click the CommandButton and it
should work if you followed the steps correctly.
--
HTH
Van T. Dinh
MVP (Access)
jeff said:
Van, thanks again for the reply,
This is the code I use in the command button:
Private Sub Command39_Click()
txtStartDate.Value = StartDate
txtEndDate.Value = EndDate
Query5Subform.SourceObject = Query5Subform
End Sub
The error I get is: "Variable Not Defined"
also...will this query use the StartDate and EndDate
instead of prompting?
Again, thank you for the help..I am not a beginner to
coding VB but Access is somewhat new to me.
.
Van,