Requerying form 1 after creating new record in form 2

A

Anita

I have a Data Entry form (frmLast_Updated). One of my controls is an unbound
drop-down list; when user selects an item from this list, I have AfterUpdate
code to automatically populate a bound control on the form. (I created it
this way because based on the form's underlying query, a bound drop-down
wouldn't display the data I wanted it to display.) When data is typed that is
not in the list, The NotinList Event does not trigger. AfterUpdate triggers
first -- so I have additional code in the AfterUpdate event to open a second
form (frmLast_Updated_Source) where they can add a new record that should
then be able to populate the appropriate bound control in frmLast_Updated.

A word about the second form, frmLast_Updated_Source -- it is based on a
join query and updates two separate tables. After the person enters the data,
they press a "Close" button. As the Close Button code below shows, I am
automatically updating a value in the underlying query, which causes a new
record to be added to one of the underlying join tables.

What I would like to do is save this new record, assign the primary key for
this new record to the appropriate control in the first form and have it
autopopulate with the new data.

What's happening is that the Form 2 record is saving, but Form 1 isn't
recognizing the new data, even if I manually hit Refresh inside of Form 1. It
only finds the new data if I close and reopen.

I researched other posts in this forum and based on those comments added the
DoCmd save record (2nd line of code) below, but I get an error message saying
that the record can't be saved.

Is there a better way to go about this?

Private Sub btnLast_Update_Source_OK_Click()
Me.[notes.descriptor].Value = Me.Source
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Forms!Data_Entry_Company!frmLast_Updated![Notes ID].Value =
Me.[Notes ID]
DoCmd.Close acForm, "frmLast_Updated_Source"
Forms!Data_Entry_Company!frmLast_Updated![SourceBound].SetFocus
Forms!Data_Entry_Company!frmLast_Updated![SourceBound].Requery
 
A

Anita

After doing a lot more digging in these forums, I found the answer, and
thought I'd post it in case anyone else experiences a similar problem --
namely, I had a data entry form with a drop-down list. To add a new record
for the list, I automatically opened a second form to enter new records. I
was having trouble updating my first form with this new info: 1) could not
get the second form record to save and b) could not get the the first form to
requery.

Basically what I did was create a Load event for the second form that
plugged in all the basic information that I needed to create a new record,
then the Me.Dirty code forced the record to save -- with no error messages.

Then, on the second form, I created a button that the user clicks when she's
finished fully adding the new record. It requeries the first form and updates
the appropriate control on the first form with the new values.

Private Sub Form_Load()

If Me.NewRecord Then
Me.[Descriptor Category].Value = "Source"
Me.Source =
Forms!Data_Entry_Company!frmLast_Updated!Descriptor_Unbound.Value
Me.[notes.descriptor].Value = Me.Source

If Me.Dirty Then
Me.Dirty = False
End If
End Sub

Private Sub btnLast_Update_Source_OK_Click()
Forms!Data_Entry_Company!frmLast_Updated![Notes ID].Value = Me.[Notes ID]
DoCmd.Close acForm, "frmLast_Updated_Source"
Forms!Data_Entry_Company!frmLast_Updated![SourceBound].Requery
Forms!Data_Entry_Company!frmLast_Updated![SourceBound].SetFocus
End Sub

Anita said:
I have a Data Entry form (frmLast_Updated). One of my controls is an unbound
drop-down list; when user selects an item from this list, I have AfterUpdate
code to automatically populate a bound control on the form. (I created it
this way because based on the form's underlying query, a bound drop-down
wouldn't display the data I wanted it to display.) When data is typed that is
not in the list, The NotinList Event does not trigger. AfterUpdate triggers
first -- so I have additional code in the AfterUpdate event to open a second
form (frmLast_Updated_Source) where they can add a new record that should
then be able to populate the appropriate bound control in frmLast_Updated.

A word about the second form, frmLast_Updated_Source -- it is based on a
join query and updates two separate tables. After the person enters the data,
they press a "Close" button. As the Close Button code below shows, I am
automatically updating a value in the underlying query, which causes a new
record to be added to one of the underlying join tables.

What I would like to do is save this new record, assign the primary key for
this new record to the appropriate control in the first form and have it
autopopulate with the new data.

What's happening is that the Form 2 record is saving, but Form 1 isn't
recognizing the new data, even if I manually hit Refresh inside of Form 1. It
only finds the new data if I close and reopen.

I researched other posts in this forum and based on those comments added the
DoCmd save record (2nd line of code) below, but I get an error message saying
that the record can't be saved.

Is there a better way to go about this?

Private Sub btnLast_Update_Source_OK_Click()
Me.[notes.descriptor].Value = Me.Source
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Forms!Data_Entry_Company!frmLast_Updated![Notes ID].Value =
Me.[Notes ID]
DoCmd.Close acForm, "frmLast_Updated_Source"
Forms!Data_Entry_Company!frmLast_Updated![SourceBound].SetFocus
Forms!Data_Entry_Company!frmLast_Updated![SourceBound].Requery
 

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