Error with form.requery (no current record)

H

h3llz

I want to dump all information within the table and requery the form, and i
get error no current record, please help! :)

.MoveLast
.MoveFirst
I = 1
Do While I <= .RecordCount
basketID = QryDat.Fields.Item("basketID")
productID = QryDat.Fields.Item("productID")
subtotal = QryDat.Fields.Item("subtotal")
quantity = QryDat.Fields.Item("quantity")
DoCmd.RunSQL ("INSERT INTO tblBasketsContent VALUES
(basketID,productID,subtotal,quantity);")
.MoveNext
I = (I + 1)
Loop
'DoCmd.OpenReport "invoice", acPreview
DoCmd.RunSQL ("UPDATE tblBasketContent SET deleted=True;")
DoCmd.RunSQL ("INSERT INTO tblBaskets (total) VALUES ('0');")
Form.Requery
 
P

Paul Shapiro

You didn't say which line of code is causing the error, but I would replace
the Do While I <= .Recordcount
with Do While Not .eof.
Do While Not .eof
basketID = QryDat.Fields.Item("basketID")
productID = QryDat.Fields.Item("productID")
subtotal = QryDat.Fields.Item("subtotal")
quantity = QryDat.Fields.Item("quantity")
DoCmd.RunSQL ("INSERT INTO tblBasketsContent VALUES
(basketID,productID,subtotal,quantity);")
.MoveNext
Loop

Better still would be replacing the procedural code that looks through the
recordset with an append query that just copies the data set from the source
to the destination.
 
H

h3llz

The Form.Requery is causing the error because it went from records within the
table to none.
 
P

Paul Shapiro

I'm not sure what your Form variable is set to? I assume this is a parameter
being passed into a subroutine? If not, and the code is running in the form
you are requerying, the syntax would be Me.Requery. Form seems a
questionable choice for a variable name since it's a reserved word. Maybe
try changing that to frmTemp, or frm, or something else.There's nothing
wrong with requerying a form that doesn't have data.

Did you step through the code with the debugger? An error for No Current
Record sounds more like an issue with a recordset operation, for example,
..MoveLast/.MoveFirst/.Fields when there aren't any records or the recordset
is positioned to .bof or .eof.
 

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