Jqws
Jqws

Reputation: 1

How to Requery a Subform which is a Junction Table

Just got a quick question. I have a junction table (Junction_Table with Song_ID and Artist_ID), and I have it as a subform in a form (Song). If I click a button I have set up, it allows me to enter a new artist into the database, by opening the Artist Form in Add-Mode. After I have entered the Artist info, and I close the Artist form, which brings me back to my Song Form, the Junction Table field for Artist_ID has not refreshed with the new Artist that was just entered. How could I refresh (Requery) this field in the Subform. I was thinking I would put some code in the button that closes the Artist form, effectively bringing me back to the Song form. I just don't know what code I should use. I have tried a few things, like this (Which has worked in other cases I needed to requery something):

Private Sub Command16_Click()
DoCmd.Close
DoCmd.OpenForm "Junction_Table"
Forms![Junction_Table]![Artist_ID].Requery
DoCmd.Close
End Sub

My Junction Table has the Master Field of the Song_ID of the Song Table Record, and the child field is the Song_ID of the Junction Table record, which when the subform is selected, autofills the Song_ID combo box with the ID of the current Songs ID, which is really helpful. Not sure if that information was important, but I added it anyway.

Upvotes: 0

Views: 34

Answers (1)

rohrl77
rohrl77

Reputation: 3337

Try removing the first docmd.close from your code.

I think you are closing the window before the rest of your code can execute. Your code would look like this:

Private Sub Command16_Click()
DoCmd.OpenForm "Junction_Table"
Forms![Junction_Table]![Artist_ID].Requery
DoCmd.Close
End Sub

Upvotes: 1

Related Questions