Refreshing a Sub-Form

G

Guest

I have a button on the main form that duplicates a selected record in a
sub-form. The sub-form is in datasheet view.
What I need to do is refresh the sub-form so that the selected record
remains selected. This is so that if I require another copy of the same
record, all I need to do is press the duplicate button again to get the third
record. I have tried to do a requery, below, of the sub-form but it always
reverts to the first record of the sub-form being selected
How can I fix this? Any help would be appreciated.
Regards
Nick

Private Sub cmdDuplicate_Click()
On Error GoTo Err_cmdDuplicate_Click

Dim stDocName As String

stDocName = "Qry Daily Summary-Apend Continuations"
DoCmd.OpenQuery stDocName, acNormal, acEdit

[Forms]![Daily Summary]![Child3].Requery

Exit_cmdDuplicate_Click:
Exit Sub

Err_cmdDuplicate_Click:
MsgBox Err.Description
Resume Exit_cmdDuplicate_Click

End Sub
 
R

Roger Carlson

You need to save the bookmark of the record to a variable, requery the
subform, then reset the bookmark. Something like this:


Dim mybookmark As Variant
mybookmark = [Forms]![Daily Summary]![Child3].form.Bookmark
[Forms]![Daily Summary]![Child3].Requery
[Forms]![Daily Summary]![Child3].form.Bookmark = mybookmark

You may have to fiddle with the naming if I have misinterpreted your design.

--
--Roger Carlson
MS Access MVP
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L
 
G

Guest

Roger,
Worked a treat, thanks very much.

Regards
Nick

Roger Carlson said:
You need to save the bookmark of the record to a variable, requery the
subform, then reset the bookmark. Something like this:


Dim mybookmark As Variant
mybookmark = [Forms]![Daily Summary]![Child3].form.Bookmark
[Forms]![Daily Summary]![Child3].Requery
[Forms]![Daily Summary]![Child3].form.Bookmark = mybookmark

You may have to fiddle with the naming if I have misinterpreted your design.

--
--Roger Carlson
MS Access MVP
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L


Nick hfrupn said:
I have a button on the main form that duplicates a selected record in a
sub-form. The sub-form is in datasheet view.
What I need to do is refresh the sub-form so that the selected record
remains selected. This is so that if I require another copy of the same
record, all I need to do is press the duplicate button again to get the
third
record. I have tried to do a requery, below, of the sub-form but it always
reverts to the first record of the sub-form being selected
How can I fix this? Any help would be appreciated.
Regards
Nick

Private Sub cmdDuplicate_Click()
On Error GoTo Err_cmdDuplicate_Click

Dim stDocName As String

stDocName = "Qry Daily Summary-Apend Continuations"
DoCmd.OpenQuery stDocName, acNormal, acEdit

[Forms]![Daily Summary]![Child3].Requery

Exit_cmdDuplicate_Click:
Exit Sub

Err_cmdDuplicate_Click:
MsgBox Err.Description
Resume Exit_cmdDuplicate_Click

End Sub
 

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