compile error: object required

J

jb33

newbie.
this is code fired by an onchange event in my form. I've
gotten through setting the reference for DAO and removing
it for ADO, but now this.

When the code goes to fire, I get a Compile Error: Object
required message. 'thisdate =' is highlighted - the
first set statement - in the debugger. If I comment out
that line, the numdays line is highlighted. I've tried
setting to constants with the same error.

Any idea why? Something wrong with my declaration or set
statement?
tia, jb



Private Sub start_date_Change()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim numdays As Byte
Dim counter As Byte
Dim thisdate As Date

Set thisdate = Me![start_date]
Set db = CurrentDb()
Set rs = db.OpenRecordset("workdays", dbOpenDynaset)
Set numdays = Me![days_required]
Set counter = 1

Do While counter <= numdays
With rs
.AddNew
!activity_id = Forms![Phase Form]!activity_id
!Date = thisdate
.Update
End With
counter = counter + 1
thisdate = DateAdd("d", 1, thisdate)
Loop

Proc_Exit: Exit Sub
Proc_Error:
MsgBox "Error " & Err.Number & " in <procedurename>:" &
vbCrLf & _
Err.Description

Resume Proc_Exit
End Sub
 
G

Graham Mandeno

Hi JB

Only object variables (Database, Recordset, Form, etc) need the Set keyword,
so you should omit it for all but db and rs:
thisdate = Me![start_date]
Set db = CurrentDb()
Set rs = db.OpenRecordset("workdays", dbOpenDynaset)
numdays = Me![days_required]
counter = 1

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

jb33 said:
newbie.
this is code fired by an onchange event in my form. I've
gotten through setting the reference for DAO and removing
it for ADO, but now this.

When the code goes to fire, I get a Compile Error: Object
required message. 'thisdate =' is highlighted - the
first set statement - in the debugger. If I comment out
that line, the numdays line is highlighted. I've tried
setting to constants with the same error.

Any idea why? Something wrong with my declaration or set
statement?
tia, jb



Private Sub start_date_Change()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim numdays As Byte
Dim counter As Byte
Dim thisdate As Date

Set thisdate = Me![start_date]
Set db = CurrentDb()
Set rs = db.OpenRecordset("workdays", dbOpenDynaset)
Set numdays = Me![days_required]
Set counter = 1

Do While counter <= numdays
With rs
.AddNew
!activity_id = Forms![Phase Form]!activity_id
!Date = thisdate
.Update
End With
counter = counter + 1
thisdate = DateAdd("d", 1, thisdate)
Loop

Proc_Exit: Exit Sub
Proc_Error:
MsgBox "Error " & Err.Number & " in <procedurename>:" &
vbCrLf & _
Err.Description

Resume Proc_Exit
End Sub
 
G

Guest

-----Original Message-----
newbie.
this is code fired by an onchange event in my form. I've
gotten through setting the reference for DAO and removing
it for ADO, but now this.

When the code goes to fire, I get a Compile Error: Object
required message. 'thisdate =' is highlighted - the
first set statement - in the debugger. If I comment out
that line, the numdays line is highlighted. I've tried
setting to constants with the same error.

Any idea why? Something wrong with my declaration or set
statement?
tia, jb



Private Sub start_date_Change()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim numdays As Byte
Dim counter As Byte
Dim thisdate As Date

Set thisdate = Me![start_date]
Set db = CurrentDb()
Set rs = db.OpenRecordset("workdays", dbOpenDynaset)
Set numdays = Me![days_required]
Set counter = 1

Do While counter <= numdays
With rs
.AddNew
!activity_id = Forms![Phase Form]!activity_id
!Date = thisdate
.Update
End With
counter = counter + 1
thisdate = DateAdd("d", 1, thisdate)
Loop

Proc_Exit: Exit Sub
Proc_Error:
MsgBox "Error " & Err.Number & " in <procedurename>:" &
vbCrLf & _
Err.Description

Resume Proc_Exit
End Sub
.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top