Access and Fields of Recordsets using DAO3.6 [Resolved]
Hi,
I'm having a problem retrieving fields from a recordset when using SQL in access. My code is this
Code:
varSQL = "SELECT * FROM tblemployees"
Set db = CurrentDb
Set rs = db.OpenRecordset(varSQL, dbOpenDynaset, dbReadOnly)
rs.MoveFirst
Do While Not rs.EOF
MsgBox rs.Fields("lastcontactdate")
If rs.Fields("lastcontactdate") < varCompareDate Then
varcount = varcount + 1
rs.MoveNext
Else
rs.MoveNext
End If
Loop
the rs.fields("lastcontactdate") line always seems to bring up an error "Item not found in this collection". Any thoughts on a speedy resolution?
Re: Access and Fields of Recordsets using DAO3.6
Make sure you have a field called lastcontactdate in tblemployees, and that it's all spelled correctly.
Then check the recordset. One way to do this is to put a Stop statement after the line Set rs = db.OpenRecordset..., then check the Locals window. You should see an entry called rs. Expand the plus sign, then the Fields plus sign. Your fields are called Item 1, Item 2, etc. Expand them until you find one with the Name value of lastcontactdate. If it's not there, it's not in your recordset.
Re: Access and Fields of Recordsets using DAO3.6
Ah, you're right. Simple case of mis-spelling.
:blush:
Thanks