Object required error

  • Thread starter Thread starter Geoff
  • Start date Start date
G

Geoff

Hi everyone,

I have written the code below and whenever it runs I get a compile error,
"Object Required" and when I chose to debug, the highlighted line is 'set
totfullday = me.daytotal'. I've tried testing out what exactly the problem
is by running some code that just has the DIM and SET statement similar to
below, and I get the same error. Obviously I'm missing something very stupid
but I can't see what. I've researched this and many people say to ensure the
DAO recordset is active, and I have made sure it is.

There is other code right above this which works fine and some of it was
given to me by someone else, and the first line is:
Private Sub Form_BeforeInsert(Cancel As Integer)

I don't know what 'cancel as integer' means but could that be causing this
problem? Just a thought, as anything with the word 'cancel' in must be
suspicious. :)

I'm sure some of the rest of the code is wrong too but I'll work on that.
I'm just trying to sort this out bit by bit so I can understand it. However,
if anyone fancies going through the rest of the code and telling me what
else is wrong, I wouldn't complain. :)

----------
'Setup variables
Dim totfullday As Single
Dim a As Byte
'Set focus to first subform record
DoCmd.GoToRecord , , acFirst
'Set totfullday to daytotal in first subform record
Set totfullday = Me.daytotal
For a = 1 To (Me.RecordsetClone.RecordCount) - 1
'Set focus to next subform record
DoCmd.GoToRecord , , acNext
'Set totfullday to what it was plus daytotal for next subform record
Set totfullday = totfullday + Me.daytotal
Next a
[runtotal] = totfullday
 
Hi Geoff,

Try removing the word 'Set' from the statement so that it simply reads

totfullday = me.daytotal

Set assigns an object reference from one object or object variable to
another.

Regarding this procedure header:

Private Sub Form_BeforeInsert(Cancel As Integer)

The event header is usually created for you when you select [Event
Procedure] for one of the event properties via the form designer. Cancel is
a special parameter which when assigned the value of true, cancels the
event. So if your code assigns true to Cancel in this event, the record will
not be inserted. This is true for any cancelable event.

Here is an example from Access Help:

Private Sub Form_BeforeInsert(Cancel As Integer)
If MsgBox("Insert new record here?", _
vbOKCancel) = vbCancel Then
Cancel = True
End If
End Sub

If the user hits the cancel button in response to the message box the event
is cancelled.
 
Sandra Daigle said:
Hi Geoff,

Try removing the word 'Set' from the statement so that it simply reads

totfullday = me.daytotal

Set assigns an object reference from one object or object variable to
another.

Regarding this procedure header:

Private Sub Form_BeforeInsert(Cancel As Integer)

The event header is usually created for you when you select [Event
Procedure] for one of the event properties via the form designer. Cancel is
a special parameter which when assigned the value of true, cancels the
event. So if your code assigns true to Cancel in this event, the record will
not be inserted. This is true for any cancelable event.


Hi Sandra. Thanks very much for that. I've removed the word 'set' and that
part of my code works fine now. In fact the rest of the code, to my
surprise, seems to be working too!

I understand what you said about 'cancel as integer' now too. There is in
fact a 'cancel = true' command in the previous bit of code (written by
someone else) in that sub, so that explains it.

Thanks for the quick reply Sandra and for explaining it all to me in plain
English. :)

Geoff.
 
Geoff said:
Hi Sandra. Thanks very much for that. I've removed the word 'set' and
that part of my code works fine now. In fact the rest of the code, to
my surprise, seems to be working too!

I understand what you said about 'cancel as integer' now too. There
is in fact a 'cancel = true' command in the previous bit of code
(written by someone else) in that sub, so that explains it.

Thanks for the quick reply Sandra and for explaining it all to me in
plain English. :)

Anytime, glad to help!
 
Back
Top