Error 3021--why?

Theguyinthehat

Registered User.
Local time
Today, 04:34
Joined
Aug 17, 2009
Messages
46
I really don't get why it can't find the record. I've checked spellings and everything. LotNumber is a text-formatted field, so that's right. Can anyone spot the problem? In the past I've used invisible text boxes to host the time, and I could do it again, but I'm sick of skirting bugs I don't understand... Here's the code.


Private Sub cmdSave_Click()
Dim db As Object
Dim time As Object
Set db = CurrentDb
Set time = db.OpenRecordset("SELECT [Time JobEntry] FROM dptdata WHERE [LotNumber] = '" & Me.txtLotNumber & "'")
time.Edit
time("Time JobEntry") = Now()
time.Update
...
End sub
 
Try being explicit:
Code:
Private Sub cmdSave_Click()
Dim db As [COLOR="red"]DAO.Database[/COLOR]
Dim time As [COLOR="Red"]DAO.Recordset[/COLOR]
Set db = CurrentDb
Set time = db.OpenRecordset("SELECT [Time JobEntry] FROM dptdata WHERE [LotNumber] = '" & Me.txtLotNumber & "'")
time.Edit
time("Time JobEntry") = Now()
time.Update
...
End sub
 
Theguyinthehat,

I'd simply:

Code:
CurrentDb.Execute "Update dptdata " & _
                  "Set    [Time JobEntry] = Now() " & _
                  "Where  [LotNumber] = '" & Me.txtLotNumber & "'")

I think your original problem is declaring time (RESERVED WORD) as Object.

I'd choose a new name and use --> Dim NewName As DAO.Recordset

Wayne
 
I tried multiple names for the object, and made explicit the DAO (though its higher on the references)--neither worked. The problem begins at time.edit (now t.edit)-- It seems to access the records perfectly.
 
Wait, I figured it out. The record hadn't been created yet--Nothing is saved to the table until the bulk of the code runs. My bad haha.
 
Wait, I figured it out. The record hadn't been created yet--Nothing is saved to the table until the bulk of the code runs. My bad haha.
tongueout.jpg
 

Users who are viewing this thread

Back
Top Bottom