Nigel,
If the ProcessDate really is a date and the Completed field is a Boolean, then
this should work.
You were right in needing the # delimiters.
But the DLookup can return a Null. To handle that properly, the DLookUp should be assigned to a variant, OR use
the Nz function to provide a value.
I feel the recordset is easier.
hth,
Wayne
If the ProcessDate really is a date and the Completed field is a Boolean, then
this should work.
Code:
Dim rst As DAO.Recordset
Dim sql As String
sql = "Select * " & _
"From MonthlyTbl " & _
"Where [ProcessDate] Between #" & CDate(Month(DateAdd("m", -1, Date)) & "/5/" & Year(DateAdd("m", -1, Date))) & "# AND " & _
" #" & CDate(Month(Date) & "/4/" & Year(Date)) & "# And "" & _
" Completed"
Set rst = CurrentDb.OpenRecordset(sql)
If rst.EOF And rst.BOf Then
MsgBox "There are none completed within the last month."
Exit Sub
End If
'
' Loop through the (at least one) ProcessIDs that are completed.
'
While Not rst.EOF And Not rst.BOF
MsgBox "This ProcessID was completed." & rst!ProcessID
rst.MoveNext
Wend
You were right in needing the # delimiters.
But the DLookup can return a Null. To handle that properly, the DLookUp should be assigned to a variant, OR use
the Nz function to provide a value.
I feel the recordset is easier.
hth,
Wayne