G
Goldar
I am trying to update a table with data from a query, but I keep getting
errors like "invalid command" ,etc. What I have is:
My query calculates a sum for each type of record in another table (TOTAL).
I have a master table (MASTER) I want to update with these sums. My VBA code
is:
Case 1-- using seek, edit and update
rstSum=db.openRecordset(qryBudgetAsTotals,dbOpenDynaset)
rst=db.openrecordset(master,dbOpenTable)
rstSum.index="Primary Key"
rst.MoveLast
rst.MoveFirst
with rst
do while not .eof
.seek ="=",rst![Key1],rst![Key2]
if not .nomatch then
.edit
.![Total field] = rstSum![Total field]
.update
endif
.movenext
.loop
' I never get this far. The code compiles ok, but I get errors trying to seek
Alternatively, I tried the same code using FindFirst with a similar result.
The code is
CASE 2--Using FindFirst logic
rstSum=db.openRecordset(qryBudgetAsTotals,dbOpenDynaset)
rst=db.openrecordset(master,dbOpenTable)
rst.MoveLast
rst.MoveFirst
with rst
do while not .eof
findfirst "[key1]='" & rstSum![Key1] & "' and [Key2]='" &
rstSum![key2] & "'"
if not .nomatch then
.edit
.![Total field] = rstSum![Total field]
.update
endif
.movenext
.loop
I know I could do this by using a query or two, but why don't these work?
Thanks for your help...
errors like "invalid command" ,etc. What I have is:
My query calculates a sum for each type of record in another table (TOTAL).
I have a master table (MASTER) I want to update with these sums. My VBA code
is:
Case 1-- using seek, edit and update
rstSum=db.openRecordset(qryBudgetAsTotals,dbOpenDynaset)
rst=db.openrecordset(master,dbOpenTable)
rstSum.index="Primary Key"
rst.MoveLast
rst.MoveFirst
with rst
do while not .eof
.seek ="=",rst![Key1],rst![Key2]
if not .nomatch then
.edit
.![Total field] = rstSum![Total field]
.update
endif
.movenext
.loop
' I never get this far. The code compiles ok, but I get errors trying to seek
Alternatively, I tried the same code using FindFirst with a similar result.
The code is
CASE 2--Using FindFirst logic
rstSum=db.openRecordset(qryBudgetAsTotals,dbOpenDynaset)
rst=db.openrecordset(master,dbOpenTable)
rst.MoveLast
rst.MoveFirst
with rst
do while not .eof
findfirst "[key1]='" & rstSum![Key1] & "' and [Key2]='" &
rstSum![key2] & "'"
if not .nomatch then
.edit
.![Total field] = rstSum![Total field]
.update
endif
.movenext
.loop
I know I could do this by using a query or two, but why don't these work?
Thanks for your help...