setting recordset when switching from subform to main form

O

OD

Hi

I have an unbound form being poulated by a query when opened. I have a
routine to add records into this database by calling a subform and entering
the information necessary. When saving I would like the main form to show the
record that the subform just entered. I haven't been able to find which
routine or how to do this. Any thoughts are greatly appreciated. Thank you
 
D

Dale Fye

When you say "calling a subform", do you really mean a popup form?

If so, then prior to closing the PopUp form, you need to save the current
record

me.dirty = false

Then capture the ID of the primary key for that new record ;it might look
like:

lngPKValue = me.ID

Then, you need to requery the main form, and find the record you just added.
This might look like:

Forms!frmMainForm.requery
Dim rs as Dao.Recordset
set rs = forms!frmMainForm.recordsetclone
rs.findfirst "PKField = " & lngPKValue
if rs.nomatch then
msgbox "unable to locate the new record"
else
forms!frmMainForm.Bookmark = rs.bookmark
endif
rs.close
set rs = nothing

I would generally put all of this code in the Click event of a Save button
on the popup form.
 
O

OD

Thank you. I'll give this a try. One of my stumbling blocks has been where to
put the code to do this. Thanks
 
D

Dale Fye

When I have a continuous form, I generally add buttons in the forms footer to
Add or Edit. When the user clicks on one of those buttons I popup the data
entry form and either point it to the record that has the focus in the
continuous form, or point it to a new record.

Then, on the data entry form, I generally have Cancel, Save, and Close
buttons, which I use to write (or not in the case of cancel) the new record
or edits to the old record, close the data entry form, requery the continuous
form (to reflect the added record or edits), and then set the pointer to the
record that was added or edited.
 

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