Can't assign a value to object

S

Steve S

When I run the code below I get the runtime error "You can't assign a value
to this object" The error happens on the line labeled (A).

If I un-comment the first line of code, labeled (B) I do not get the error.
I have fought this for days and am currently running the code OK but having
to use the hokey code in line (B) bothers me. I just stumbled across this
'fix' by accident while troubleshooting the issue.

does anyone have an idea of why the error happens and a possible better
solution??

Also how sould I trap and display the error code number as well as the error
text?



----------------------------------------------------
' Me.LinkTo_ID = Me.LinkTo_ID ' (B) un-comment to stop error

intLink = 46

' Get record That may be linked
Dim db As DAO.Database
Dim rcd As DAO.Recordset
Set db = CurrentDb
Set rcd = db.OpenRecordset("Contests", dbOpenDynaset)
rcd.FindFirst "[Contest ID]=" & intLink
rcd.Edit

rcd![LinkTo ID] = [Forms]![Define Contest]![Contest ID]
Me![LinkTo ID] = intLink ' (A) error happens here

rcd.Update
Set db = Nothing
------------------------------------------------------------
 
K

Ken Snell \(MVP\)

Is the "LinkTo ID" object a field in the form's recordsource query? If yes,
change the ! to . in the (A) line.
 
M

Mike Painter

Steve said:
When I run the code below I get the runtime error "You can't assign a
value to this object" The error happens on the line labeled (A).

If I un-comment the first line of code, labeled (B) I do not get the
error. I have fought this for days and am currently running the code
OK but having to use the hokey code in line (B) bothers me. I just
stumbled across this 'fix' by accident while troubleshooting the
issue.

does anyone have an idea of why the error happens and a possible
better solution??

Also how sould I trap and display the error code number as well as
the error text?



----------------------------------------------------
' Me.LinkTo_ID = Me.LinkTo_ID ' (B) un-comment to stop error

intLink = 46

' Get record That may be linked
Dim db As DAO.Database
Dim rcd As DAO.Recordset
Set db = CurrentDb
Set rcd = db.OpenRecordset("Contests", dbOpenDynaset)
rcd.FindFirst "[Contest ID]=" & intLink
rcd.Edit

rcd![LinkTo ID] = [Forms]![Define Contest]![Contest ID]
Me![LinkTo ID] = intLink ' (A) error happens here

rcd.Update
Set db = Nothing
------------------------------------------------------------
I don't see wher you Dimensioned intLink.
Does it have any value?
 
S

Steve S

Hi Mike,

intLink is a public variable dimd in MyVariables as:

Public intLink as Integer

In the sample code see:
intLink = 46
--
Steve S


Mike Painter said:
Steve said:
When I run the code below I get the runtime error "You can't assign a
value to this object" The error happens on the line labeled (A).

If I un-comment the first line of code, labeled (B) I do not get the
error. I have fought this for days and am currently running the code
OK but having to use the hokey code in line (B) bothers me. I just
stumbled across this 'fix' by accident while troubleshooting the
issue.

does anyone have an idea of why the error happens and a possible
better solution??

Also how sould I trap and display the error code number as well as
the error text?



----------------------------------------------------
' Me.LinkTo_ID = Me.LinkTo_ID ' (B) un-comment to stop error

intLink = 46

' Get record That may be linked
Dim db As DAO.Database
Dim rcd As DAO.Recordset
Set db = CurrentDb
Set rcd = db.OpenRecordset("Contests", dbOpenDynaset)
rcd.FindFirst "[Contest ID]=" & intLink
rcd.Edit

rcd![LinkTo ID] = [Forms]![Define Contest]![Contest ID]
Me![LinkTo ID] = intLink ' (A) error happens here

rcd.Update
Set db = Nothing
------------------------------------------------------------
I don't see wher you Dimensioned intLink.
Does it have any value?
 
S

Steve S

Yes, "LinkTo ID" is a Textbox on the form and is bound to a field in the
form's recordsource query. I have tried replacing the "." with "!" and have
also changed the name of the textbox so it is not identical to the name of
the field it is bound to.

Tried this early on but still the only way I can get 'error'free' is to
execute the line marked (B)
--
Steve S


Ken Snell (MVP) said:
Is the "LinkTo ID" object a field in the form's recordsource query? If yes,
change the ! to . in the (A) line.
--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


Steve S said:
When I run the code below I get the runtime error "You can't assign a
value
to this object" The error happens on the line labeled (A).

If I un-comment the first line of code, labeled (B) I do not get the
error.
I have fought this for days and am currently running the code OK but
having
to use the hokey code in line (B) bothers me. I just stumbled across this
'fix' by accident while troubleshooting the issue.

does anyone have an idea of why the error happens and a possible better
solution??

Also how sould I trap and display the error code number as well as the
error
text?



----------------------------------------------------
' Me.LinkTo_ID = Me.LinkTo_ID ' (B) un-comment to stop error

intLink = 46

' Get record That may be linked
Dim db As DAO.Database
Dim rcd As DAO.Recordset
Set db = CurrentDb
Set rcd = db.OpenRecordset("Contests", dbOpenDynaset)
rcd.FindFirst "[Contest ID]=" & intLink
rcd.Edit

rcd![LinkTo ID] = [Forms]![Define Contest]![Contest ID]
Me![LinkTo ID] = intLink ' (A) error happens here

rcd.Update
Set db = Nothing
 
K

Ken Snell \(MVP\)

Are you running this code in an event procedure? Which one, if yes?
--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


Steve S said:
Yes, "LinkTo ID" is a Textbox on the form and is bound to a field in the
form's recordsource query. I have tried replacing the "." with "!" and
have
also changed the name of the textbox so it is not identical to the name of
the field it is bound to.

Tried this early on but still the only way I can get 'error'free' is to
execute the line marked (B)
--
Steve S


Ken Snell (MVP) said:
Is the "LinkTo ID" object a field in the form's recordsource query? If
yes,
change the ! to . in the (A) line.
--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


Steve S said:
When I run the code below I get the runtime error "You can't assign a
value
to this object" The error happens on the line labeled (A).

If I un-comment the first line of code, labeled (B) I do not get the
error.
I have fought this for days and am currently running the code OK but
having
to use the hokey code in line (B) bothers me. I just stumbled across
this
'fix' by accident while troubleshooting the issue.

does anyone have an idea of why the error happens and a possible better
solution??

Also how sould I trap and display the error code number as well as the
error
text?



----------------------------------------------------
' Me.LinkTo_ID = Me.LinkTo_ID ' (B) un-comment to stop error

intLink = 46

' Get record That may be linked
Dim db As DAO.Database
Dim rcd As DAO.Recordset
Set db = CurrentDb
Set rcd = db.OpenRecordset("Contests", dbOpenDynaset)
rcd.FindFirst "[Contest ID]=" & intLink
rcd.Edit

rcd![LinkTo ID] = [Forms]![Define Contest]![Contest ID]
Me![LinkTo ID] = intLink ' (A) error happens here

rcd.Update
Set db = Nothing
 
S

Steve S

Yes, it is in the 'lostFocus' event procedure of a text box named 'StartDate' .
--
Steve S


Ken Snell (MVP) said:
Are you running this code in an event procedure? Which one, if yes?
--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


Steve S said:
Yes, "LinkTo ID" is a Textbox on the form and is bound to a field in the
form's recordsource query. I have tried replacing the "." with "!" and
have
also changed the name of the textbox so it is not identical to the name of
the field it is bound to.

Tried this early on but still the only way I can get 'error'free' is to
execute the line marked (B)
--
Steve S


Ken Snell (MVP) said:
Is the "LinkTo ID" object a field in the form's recordsource query? If
yes,
change the ! to . in the (A) line.
--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


When I run the code below I get the runtime error "You can't assign a
value
to this object" The error happens on the line labeled (A).

If I un-comment the first line of code, labeled (B) I do not get the
error.
I have fought this for days and am currently running the code OK but
having
to use the hokey code in line (B) bothers me. I just stumbled across
this
'fix' by accident while troubleshooting the issue.

does anyone have an idea of why the error happens and a possible better
solution??

Also how sould I trap and display the error code number as well as the
error
text?



----------------------------------------------------
' Me.LinkTo_ID = Me.LinkTo_ID ' (B) un-comment to stop error

intLink = 46

' Get record That may be linked
Dim db As DAO.Database
Dim rcd As DAO.Recordset
Set db = CurrentDb
Set rcd = db.OpenRecordset("Contests", dbOpenDynaset)
rcd.FindFirst "[Contest ID]=" & intLink
rcd.Edit

rcd![LinkTo ID] = [Forms]![Define Contest]![Contest ID]
Me![LinkTo ID] = intLink ' (A) error happens here

rcd.Update
Set db = Nothing
 

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

Top