recordset clone

B

Bill

I'm trying to set the values of a checkbox on a subform
with the code below. I get a "Item not found in this
collection" error and it highlights the ".[Auto_Restock]
= -1" line (6th from bottom). As if that control isn't
part of the recordset. Any ideas?


Dim rst As Variant

Forms!TT2!OrderDetailSubform.SetFocus
Set rst = Me.RecordsetClone


If rst.RecordCount > 0 Then
rst.MoveLast
rst.MoveFirst

With rst
Do While Not .EOF
.Edit
.[Auto_Restock] = -1
.MoveNext
Loop

Set rst = Nothing
.Close
End With
 
K

Ken Snell [MVP]

Is it possible that the "actual" name is Auto Restock (not Auto_Restock) ?
ACCESS replaces the space with _ when the field or control is used as part
of the form's controls collection, so it may be misleading you?
 
M

Marshall Barton

Bill said:
I'm trying to set the values of a checkbox on a subform
with the code below. I get a "Item not found in this
collection" error and it highlights the ".[Auto_Restock]
= -1" line (6th from bottom). As if that control isn't
part of the recordset. Any ideas?


Dim rst As Variant

Forms!TT2!OrderDetailSubform.SetFocus
Set rst = Me.RecordsetClone


If rst.RecordCount > 0 Then
rst.MoveLast
rst.MoveFirst

With rst
Do While Not .EOF
.Edit
.[Auto_Restock] = -1
.MoveNext
Loop

Set rst = Nothing
.Close
End With


You need a ! (not a .) infront of the field name.

You also forgot the .Update before the MoveNext.

Close the recordset before setting the variable to Nothing.

.Close : Set rs = Nothing
 
K

Ken Snell [MVP]

Good catch, Marsh!

--

Ken Snell
<MS ACCESS MVP>

Marshall Barton said:
Bill said:
I'm trying to set the values of a checkbox on a subform
with the code below. I get a "Item not found in this
collection" error and it highlights the ".[Auto_Restock]
= -1" line (6th from bottom). As if that control isn't
part of the recordset. Any ideas?


Dim rst As Variant

Forms!TT2!OrderDetailSubform.SetFocus
Set rst = Me.RecordsetClone


If rst.RecordCount > 0 Then
rst.MoveLast
rst.MoveFirst

With rst
Do While Not .EOF
.Edit
.[Auto_Restock] = -1
.MoveNext
Loop

Set rst = Nothing
.Close
End With


You need a ! (not a .) infront of the field name.

You also forgot the .Update before the MoveNext.

Close the recordset before setting the variable to Nothing.

.Close : Set rs = 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

Similar Threads


Top