Listbox doesn't requery after adding a new record

TravelingCat

Registered User.
Local time
Today, 17:08
Joined
Feb 22, 2010
Messages
42
Hi,
I have a mainform, and a subform in it. The main form contains current event details. The subform has ListBox control which contains assignments of that event. To add a new assignment, you click on button and another form opens. The thing is, if the listbox already contains some assignments, the new one are added and shown without a problem. But if the listbox is still empty and i'm adding a first, it doesn't requery, only if i exit the form and reload it. I would really appreciate if someone could point me to the solution.
I also noticed that the same problem appears in my other listboxes as well.
Here's the code behind the "add new assignment" button:

Code:
Private Sub btnNewAssignment_Click() 
Text = Forms(Parent.Name).Controls("eventNum") 
strRow = ListAssignments.ListIndex + 1 
strAssignNum = Nz(ListAssignments.Column(7)) 
DoCmd.OpenForm "frmNewAssignment", , , , acFormAdd, acDialog, 1 & ";" & Text
ListAssignments.Requery
End Sub
 
You might have to look at the form events, like AfterUpdate or Before Update or Dirty and add your list box requery statement there.
 
Thanks, but it always have been very difficult for me with these events, i never know when they fire..
I also have reports listbox on the same form, so i've put a breakpoint on the form's after and before update, it never fired.
Would appreciate more ideas..
 
Try putting "Me." in front of your "ListAssignments.requery" so that it looks like this:

Me.ListAssignments.Reuqery
 
I didn't write it because it has to do with my program specifically, so it wont help anyone i think. Anyway, the listbox is inside frmAssignments, which is the subform of frmEvents. In order for it to display the right assignments, it should get current event number. The problem was with the event num variable, it wasn't correct, so it always requeried some other events and not the current. I simply fixed the listbox's row source.
 

Users who are viewing this thread

Back
Top Bottom