Requery list box upon return from form

S

sharontodd

I am in a form (Winners) that views data via two list boxes "first_data" and
"first_data2" that was entered in a different form (Reg). There is a command
button that opens Reg so the data can be corrected if needed. How do I get
the two list boxes to update when returning from the Reg form. I tried to
Requery both boxes at a variety of locations. I have the following code for
On click (showing all locations I've tried to Requery). Do I need to do
something else/somewhere else?

Private Sub First_Data_Update_Click()
On Error GoTo Err_First_Data_Update_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Registrations"

stLinkCriteria = "[Reg#]=" & Me![First]
DoCmd.OpenForm stDocName, , , stLinkCriteria
Me.First_data.Requery
Me.first_data2.Requery
Exit_First_Data_Update_Click:
Me.First_data.Requery
Me.first_data2.Requery
Exit Sub

Err_First_Data_Update_Click:
MsgBox Err.Description
Resume Exit_First_Data_Update_Click

Me.First_data.Requery
Me.first_data2.Requery

End Sub
 
J

Jim Burke in Novi

I would put the requery code in the Close Event of the Reg form. If the Reg
form can only be opened from the Winners form, simply requery the listboxes.
If it's possible to get to the Reg form from other places than the Winners
form, then you'd need to check to see if the Winners form is open before
requerying. So in the Reg form's Close Event you want something like:

If CurrentProject.AllForms("Winners").IsLoaded Then
Forms!WInners!First_data.Requery
Forms!WInners!First_data2.Requery
End If

If you know that you're always going back to the Winners form then you don't
need to check to see if it is Loaded.
 
S

sharontodd

There are other possible entry points to Reg so I entered the code you
suggested. I get a message "Object doesn't support this property or method".
Here is the code I have for the close command button in Reg.

Private Sub Close_Registr_Click()
On Error GoTo Err_Close_Registr_Click

If CurrentProject.AllForm("Division_Winners").IsLoaded Then
Forms!Winners!First_data.Requery
Forms!Winners!second_data.Requery
Forms!Winners!third_data.Requery
Forms!Winners!fourth_data.Requery
Forms!Winners!fifth_data.Requery
End If

Me.Dirty = False

DoCmd.Close

Exit_Close_Registr_Click:
Exit Sub

Err_Close_Registr_Click:
MsgBox Err.Description
Resume Exit_Close_Registr_Click

End Sub

Thanks
Sharontodd

Jim Burke in Novi said:
I would put the requery code in the Close Event of the Reg form. If the Reg
form can only be opened from the Winners form, simply requery the listboxes.
If it's possible to get to the Reg form from other places than the Winners
form, then you'd need to check to see if the Winners form is open before
requerying. So in the Reg form's Close Event you want something like:

If CurrentProject.AllForms("Winners").IsLoaded Then
Forms!WInners!First_data.Requery
Forms!WInners!First_data2.Requery
End If

If you know that you're always going back to the Winners form then you don't
need to check to see if it is Loaded.


sharontodd said:
I am in a form (Winners) that views data via two list boxes "first_data" and
"first_data2" that was entered in a different form (Reg). There is a command
button that opens Reg so the data can be corrected if needed. How do I get
the two list boxes to update when returning from the Reg form. I tried to
Requery both boxes at a variety of locations. I have the following code for
On click (showing all locations I've tried to Requery). Do I need to do
something else/somewhere else?

Private Sub First_Data_Update_Click()
On Error GoTo Err_First_Data_Update_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Registrations"

stLinkCriteria = "[Reg#]=" & Me![First]
DoCmd.OpenForm stDocName, , , stLinkCriteria
Me.First_data.Requery
Me.first_data2.Requery
Exit_First_Data_Update_Click:
Me.First_data.Requery
Me.first_data2.Requery
Exit Sub

Err_First_Data_Update_Click:
MsgBox Err.Description
Resume Exit_First_Data_Update_Click

Me.First_data.Requery
Me.first_data2.Requery

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