No. AFAIK, it won't work this way as you assign a *previously created*
Recordset as the RecordSource for the Subform which prevents the filtering
by the LinkParentFields / LinkChildFields. Note that one of the Microsoft
engineers previously advised that the most efficient way to populate a
Subform is to use Table or a saved Query or an SQL String as the
RecordSource for the Subform.
I am not sure why you have to use a Recordset which is not as efficient.
Also, you have to do your own filtering rather than letting the Link Fields
to do the work for you.
--
HTH
Van T. Dinh
MVP (Access)
dwg said:
Van,
This post is lengthy, but I want to try to explain everything I have tried to get the program to work.
The form in question is based on the SalesmanTbl table with the primary
key SalesmanID. I created a subform based on the SalesTbl table with a key
of AutoID and SalesDt. SalesmanID is an index on the Sales table. I linked
the tables on SalesmanID. I then wrote an event for the subform's Load
event.
The code is below:
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Set cn = CurrentProject.AccessConnection
Set rs = New ADODB.Recordset
'With rs
Set .ActiveConnection = cn
.Source = "SELECT SMan.SalesmanID, Sales.SalesDt,
Sales.AutoID, Sales.DocFeesAmt " & _
"FROM SalesmanTbl AS SMan LEFT JOIN " & _
"[SELECT SalesmanID,SalesDt, AutoID,
(TitleFeeAmt+ArbitrationFeeAmt) AS DocFeesAmt " & _
"FROM SalesTbl " & _
"WHERE SalesDt BETWEEN " & _
" #" & DateAdd("y", -6,
CDate(Forms!PayrollWeekEndingDtFrm.WeekEndingDt.Value) - 6) & "# " & _
CDate(Forms!PayrollWeekEndingDtFrm.WeekEndingDt.Value) & "# " & _
"ORDER BY SalesmanID,SalesDt,AutoID]. AS Sales " & _
"ON SMan.SalesmanID = Sales.SalesmanID " & _
"ORDER BY Sales.SalesmanID, Sales.SalesDt, Sales.AutoID;"
.LockType = adLockOptimistic
.CursorType = adOpenForwardOnly
.CursorLocation = adUseServer
.Open
End With
Set Me.Recordset = rs
Set rs = Nothing
Set cn = Nothing
The problem with this code is that for each Salesman the entire recordset
would display i.e. the Link field wasn't working.
I tried a number of alternatives (none of which worked) and decided to use
another approach: the Database Query object and build a parameter query for
the beginning and ending date. When I hard code the dates the form/sub form
relation works great; however, I don't know the syntax for passing the
parameters via a form rather than the standard query prompt for the dates.
The query object is shown below:
SELECT SMan.SalesmanID, Sales.SalesDt, Sales.AutoID,
(Sales.TitleFeeAmt+Sales.ArbitrationFeeAmt) AS DocFeesAmt
FROM SalesTbl AS Sales RIGHT JOIN SalesmanTbl AS SMan ON Sales.SalesmanID = SMan.SalesmanID
WHERE (((Sales.SalesDt) Between WeekStartDt And WeekEndingDt))
ORDER BY SMan.SalesmanID, Sales.SalesDt, Sales.AutoID;
I have a form with a command button that passes the dates to the
form/subform correctly, but I can not get the query to recognize these
parameters. I know the data is being passed because I use it to calculate
another field on the form.
I tried various variations of your original suggestion for modifying the query. My attempts were:
Forms!"DateFrm"!"WeekEndingDt"
Forms!'DateFrm'!'WeekEndingDt'
Forms![DateFrm]![WeekEndingDt]"
Forms.[DateFrm].[WeekEndingDt]
where DateFrm is the form passing the date. I am only showing EndingDt to save typing time.
Some of these attempts gave errors when I ran the query or sometimes I got
the Send Error Report to Microsoft message.