Requery on unbound list box not working

J

jhanby1

So I have 2 separate forms: [Filter Detail] and [Add Part].

On [Filter Detail], there is a list box that displays a list of parts
for a particular filter. When I click on the Add Part command button,
the [Add Part] form opens up.

On [Add Part], I enter in the information for that particular part,
click the Add and Close command button, and requery the list box of
parts on [Filter Detail]. Here is my code for [Filter Detail]:

Private Sub cmdAddPart_Click()

setUIUpdateVars

DoCmd.OpenForm "Add Part", acNormal, , , , , "ADD:" &
Me.txtFilterId & ":"

Me.cboGroup = Null
setPartGroup ("All")
refreshData
Me!cboGroup.Requery
End Sub

Public Function refreshData()
calcFilterTotal

If (IsNull(Me!cboGroup.Column(0))) Then
setPartGroup ("All")
Else
setPartGroup (Me!cboGroup.Column(0))
End If

Me!lstParts.Requery

End Function

Here is code from [Add Part]:

Private Sub cmdAddClose_Click()

If canAddPart Then
addPart

DoCmd.Close acForm, "Add Part"
End If

End Sub

Don't worry about the other functions you see in the code
(setPartGroup, calcFilterTotal, canAddPart, addPart), they shouldn't
affect my problem. I tried commenting them out to see if it they were
tripping up the process, and no luck, so there is something else I am
missing. After the part is added from the [Add Part] form, the listbox
does not show the addition until I click a refresh button. I want the
listbox to immediately show the change once the [Add Part] form is
closed.

Thanks for the help.
 
S

Sandra Daigle

The way you have it now, the requery is occuring before the new record gets
added. Unless you open the Add Part in dialog mode, the code after the
Openform command continues to run. You need to requery the listbox from the
close button on the Add Part form:

forms![Filter Detail].lstParts.Requery
 
G

Graham Mandeno

The problem is that your code continues to execute after the "Add Part" form
has been opened. This is normal - you can have many forms open at once and
they can all execute their code independently and asynchronously. However,
this means that the requery is done before the new record has been added.

To force a form to behave synchronously, you must open it modally by
specifying acDialog as the WindowMode (6th) argument:

DoCmd.OpenForm "Add Part", acNormal, , , , acDialog, _
"ADD:" & Me.txtFilterId & ":"

The next line of code will then not be executed until the form you have
opened is either closed or made invisible.
 
J

jhanby1

I tried both of those solutions and they did not seem to work. I have a
"Show All" button on the [Filter Detail] form, and when I click it a
couple of times to requery the listbox, the added part eventually shows
up. It seems like the part is not being added to the table until a
couple of seconds after all the procedures are finished running.
Therefore, when i click the Show All button, the part eventually shows
up.

So my question is still the same, how can I make it an immediate update
in the listbox?
 

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