L
Len B
I have a proc attached to the OnClick event of a button on a form.
In summary the procedure performs these tasks
01 Set dbs = CurrentDb()
02 Set rstBatch = dbs.OpenRecordset(stSelectB, dbOpenDynaset)
03 Set rstEquip = dbs.OpenRecordset(stSelectE, dbOpenDynaset)
04 Set rstMoves = dbs.OpenRecordset("Moves")
05 rstBatch.MoveFirst
06 With rstBatch
07 Do Until .EOF
08 find the matching record in rstEquip
09 set some variables using the current batch record data
10 Append new record to rstMoves and .Update
11 With rstEquip
12 .Edit !Location=stNewLocation .Update
13 End With
14===> .Edit
15 !Processed=True
16 .Update
17 .MoveNext
18 Loop
19 End With
20 Set dbs (and rst x 3) = Nothing
The .Edit statement (14) generates Error 3027 (Db or object RO).
I have concluded that the db isn't read only since (10) & (12)
do not generate an error. The statement (02) creating the rst referenced
in (14) is virtually identical to (03). Both selection criteria strings
contain FROM, WHERE, ORDER BY clauses. (02) contains SELECT DISTINCT but
(03) contains SELECT only.
Removing the DISTINCT removes the error. There should be no need to have
the DISTINCT clause but I cannot totally discount the possibility of
duplicate records in the Batch recordset.
2 Questions -
Why does the DISTINCT make the rst RO?
How do I protect from duplicates?
TIA
In summary the procedure performs these tasks
01 Set dbs = CurrentDb()
02 Set rstBatch = dbs.OpenRecordset(stSelectB, dbOpenDynaset)
03 Set rstEquip = dbs.OpenRecordset(stSelectE, dbOpenDynaset)
04 Set rstMoves = dbs.OpenRecordset("Moves")
05 rstBatch.MoveFirst
06 With rstBatch
07 Do Until .EOF
08 find the matching record in rstEquip
09 set some variables using the current batch record data
10 Append new record to rstMoves and .Update
11 With rstEquip
12 .Edit !Location=stNewLocation .Update
13 End With
14===> .Edit
15 !Processed=True
16 .Update
17 .MoveNext
18 Loop
19 End With
20 Set dbs (and rst x 3) = Nothing
The .Edit statement (14) generates Error 3027 (Db or object RO).
I have concluded that the db isn't read only since (10) & (12)
do not generate an error. The statement (02) creating the rst referenced
in (14) is virtually identical to (03). Both selection criteria strings
contain FROM, WHERE, ORDER BY clauses. (02) contains SELECT DISTINCT but
(03) contains SELECT only.
Removing the DISTINCT removes the error. There should be no need to have
the DISTINCT clause but I cannot totally discount the possibility of
duplicate records in the Batch recordset.
2 Questions -
Why does the DISTINCT make the rst RO?
How do I protect from duplicates?
TIA