S
SuzyQ
can dlookup be used to look up a record in a recordset?
I have the following code and my dlookup statement is returning an error
"could not find table or query"... which I guess answers my question, if so,
then how can I look up the value? Do I have to iterate through the recordset?
Function writeMissingInvoices(haveData As Boolean, Optional rs As
DAO.Recordset) As Boolean
'need to account for invoices entered for a specific project on specific
date range but no labor occured in that date range
Dim rsProjects As DAO.Recordset
Dim strSQL As String
Dim strProject As String
Dim dblProjectTotal As Double
Dim booAddIt As Boolean
Dim booChecked As Boolean
Dim strDistrict As String
Dim strGroup As String
Dim strDescription As String
'first get all the invoices for the specified date range
strSQL = "SELECT tblInvoiceLineItems.ProjectToCharge,
tblInvoice.InvoiceDate, "
strSQL = strSQL & "tblInvoiceLineItems.PerUnitAmount,
tblInvoiceLineItems.Quantity, "
strSQL = strSQL & "[quantity]*[perUnitAmount] AS total "
strSQL = strSQL & "FROM tblInvoice INNER JOIN tblInvoiceLineItems ON "
strSQL = strSQL & "tblInvoice.InvoiceID = tblInvoiceLineItems.InvoiceID "
strSQL = strSQL & "WHERE ((tblInvoice.InvoiceDate) Between "
strSQL = strSQL & "#" & [Forms]![frmReports]![txtFromDate] & "# And #"
strSQL = strSQL & [Forms]![frmReports]![txtToDate] & "#) "
strSQL = strSQL & "ORDER BY tblInvoiceLineItems.ProjectToCharge "
Set rsProjects = CurrentDb.OpenRecordset(strSQL)
If Not rsProjects.EOF Then
'look in rs data set to make sure this project hasn't already been
assigned to a record amount
strProject = Nz(rsProjects!ProjectToCharge, " ")
If haveData Then 'some projects have already been handled elsewhere
booAddIt = False
booChecked = False
Else 'no projects have been handled - add all projects
booAddIt = True
booChecked = True
End If
Do While Not rsProjects.EOF
'next check to see if that project number is already handled in
the rs recordset if necessary
If strProject = Nz(rsProjects!ProjectToCharge, " ") Then 'still
on same code
If Not booChecked Then 'if code has not been checked yet,
check to see if it needs to be added
If IsNull(DLookup("[ProjectCode]", "rs", "[ProjectCode]
= '" & strProject & "'")) Then ... 'ERROR RIGHT HERE
I have the following code and my dlookup statement is returning an error
"could not find table or query"... which I guess answers my question, if so,
then how can I look up the value? Do I have to iterate through the recordset?
Function writeMissingInvoices(haveData As Boolean, Optional rs As
DAO.Recordset) As Boolean
'need to account for invoices entered for a specific project on specific
date range but no labor occured in that date range
Dim rsProjects As DAO.Recordset
Dim strSQL As String
Dim strProject As String
Dim dblProjectTotal As Double
Dim booAddIt As Boolean
Dim booChecked As Boolean
Dim strDistrict As String
Dim strGroup As String
Dim strDescription As String
'first get all the invoices for the specified date range
strSQL = "SELECT tblInvoiceLineItems.ProjectToCharge,
tblInvoice.InvoiceDate, "
strSQL = strSQL & "tblInvoiceLineItems.PerUnitAmount,
tblInvoiceLineItems.Quantity, "
strSQL = strSQL & "[quantity]*[perUnitAmount] AS total "
strSQL = strSQL & "FROM tblInvoice INNER JOIN tblInvoiceLineItems ON "
strSQL = strSQL & "tblInvoice.InvoiceID = tblInvoiceLineItems.InvoiceID "
strSQL = strSQL & "WHERE ((tblInvoice.InvoiceDate) Between "
strSQL = strSQL & "#" & [Forms]![frmReports]![txtFromDate] & "# And #"
strSQL = strSQL & [Forms]![frmReports]![txtToDate] & "#) "
strSQL = strSQL & "ORDER BY tblInvoiceLineItems.ProjectToCharge "
Set rsProjects = CurrentDb.OpenRecordset(strSQL)
If Not rsProjects.EOF Then
'look in rs data set to make sure this project hasn't already been
assigned to a record amount
strProject = Nz(rsProjects!ProjectToCharge, " ")
If haveData Then 'some projects have already been handled elsewhere
booAddIt = False
booChecked = False
Else 'no projects have been handled - add all projects
booAddIt = True
booChecked = True
End If
Do While Not rsProjects.EOF
'next check to see if that project number is already handled in
the rs recordset if necessary
If strProject = Nz(rsProjects!ProjectToCharge, " ") Then 'still
on same code
If Not booChecked Then 'if code has not been checked yet,
check to see if it needs to be added
If IsNull(DLookup("[ProjectCode]", "rs", "[ProjectCode]
= '" & strProject & "'")) Then ... 'ERROR RIGHT HERE