Form requery

P

P

Hi. I created a save button that runs the following code:

if frmMain.Dirty then frmMain.dirty = false
With frmMain
.AllowEdits = False
End With
....
set rst = frmMain.RecordsetClone
rst.Bookmark = frmMain.Bookmark
frmMain.Requery
frmMain.Bookmark = rst.Bookmark

When I click Save, the form comes up with the previous record showing, one
off the new record. How could I set the form to come up with the newly saved
record? Thank you for your help. P
 
B

Bob Quintal

Hi. I created a save button that runs the following code:

if frmMain.Dirty then frmMain.dirty = false
With frmMain
.AllowEdits = False
End With
...
set rst = frmMain.RecordsetClone
rst.Bookmark = frmMain.Bookmark
frmMain.Requery
frmMain.Bookmark = rst.Bookmark

When I click Save, the form comes up with the previous record
showing, one off the new record. How could I set the form to come
up with the newly saved record? Thank you for your help. P
Best way is to grab the primary key from the record and do a .findfirst
instead.

You could try a .movenext if the form's recordset sort order is the
order of date the entry is made, but otherwise you may wind up anywhere.

Bob.
 
A

Albert D. Kallal

You don't really give any reason why you are doing a re-query. However, a
re-query complete re-loads the reocrdset for the form, and thus any bookmark
previous to the query is going to be invalid.

Hence, you have to use the key id IF YOU MUST use a requery.

Anyreason why you don't just force a save with me.refresh? That way, you
only need one line of code:

me.Refresh
 

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