Dear All,
I hope you can help. I have been working round this problem for 2 days...
I am running the following query directly from the code:
Public Sub Test()
Dim dbs As DAO.Database
Dim MyRs As DAO.Recordset
Dim MyRsFilter As DAO.Recordset
Dim strsql As String
strsql = "SELECT Sum([quantity]*[rrp]*(1-[Salelinedisc])*(1+[vatrate])) AS Gross, Last(tblSalesHeader.CustomerID) AS LastOfCustomerID, " _
& "Last(tblSalesHeader.SalesInvDate) AS LastOfSalesInvDate, Last(tblSalesHeader.PymtMethod) AS LastOfPymtMethod, " _
& "Last(tblSalesHeader.CustomerFullName) AS LastOfCustomerFullName, tblSalesLines.SalesHeaderID, Last(tblSalesHeader.SalesInvRef) AS LastOfSalesInvRef, " _
& "Last(tblSalesHeader.TransType) AS LastOfTransType, Last(IIf([transtype]='R','Credit Note','Invoice')) AS DocDesc " _
& "FROM tblSalesHeader LEFT JOIN tblSalesLines ON tblSalesHeader.SalesInvNo = tblSalesLines.SalesHeaderID " _
& "GROUP BY tblSalesLines.SalesHeaderID;"
Set dbs = CurrentDb
Set MyRs = dbs.OpenRecordset(strsql)
With MyRs
Debug.Print strsql
.Filter = "[CustomerID]= 718"
Set MyRsFilter = MyRs.OpenRecordset
Debug.Print .RecordCount
.Close
End With
Set MyRsFilter = Nothing
Set MyRs = Nothing
Set dbs = Nothing
End Sub
If I remove the filter the query returns the correct number of records. When I apply it I get the above error message. I have tried numerous syntax with no success.
the filter on [CustomerID] should return 2 records (tested in independent query).
Any suggestions please?
:banghead:
I hope you can help. I have been working round this problem for 2 days...
I am running the following query directly from the code:
Public Sub Test()
Dim dbs As DAO.Database
Dim MyRs As DAO.Recordset
Dim MyRsFilter As DAO.Recordset
Dim strsql As String
strsql = "SELECT Sum([quantity]*[rrp]*(1-[Salelinedisc])*(1+[vatrate])) AS Gross, Last(tblSalesHeader.CustomerID) AS LastOfCustomerID, " _
& "Last(tblSalesHeader.SalesInvDate) AS LastOfSalesInvDate, Last(tblSalesHeader.PymtMethod) AS LastOfPymtMethod, " _
& "Last(tblSalesHeader.CustomerFullName) AS LastOfCustomerFullName, tblSalesLines.SalesHeaderID, Last(tblSalesHeader.SalesInvRef) AS LastOfSalesInvRef, " _
& "Last(tblSalesHeader.TransType) AS LastOfTransType, Last(IIf([transtype]='R','Credit Note','Invoice')) AS DocDesc " _
& "FROM tblSalesHeader LEFT JOIN tblSalesLines ON tblSalesHeader.SalesInvNo = tblSalesLines.SalesHeaderID " _
& "GROUP BY tblSalesLines.SalesHeaderID;"
Set dbs = CurrentDb
Set MyRs = dbs.OpenRecordset(strsql)
With MyRs
Debug.Print strsql
.Filter = "[CustomerID]= 718"
Set MyRsFilter = MyRs.OpenRecordset
Debug.Print .RecordCount
.Close
End With
Set MyRsFilter = Nothing
Set MyRs = Nothing
Set dbs = Nothing
End Sub
If I remove the filter the query returns the correct number of records. When I apply it I get the above error message. I have tried numerous syntax with no success.
the filter on [CustomerID] should return 2 records (tested in independent query).
Any suggestions please?
:banghead: