How do I add items to a multi-select listbox on the fly?

  • Thread starter Thread starter gagecres
  • Start date Start date
G

gagecres

I have a form that has a multi-select list box and a subform used to enter
new records into the table used to populate the list box. When, using the
subform, a new record is added to the underlying table used to populate the
list box, how do I get the newly entered record to appear in the list box?
Is it just a matter of doing a requery? If so, what is the code,
"me.requery"? Also, where do I put the code?
 
Is it just a matter of doing a requery? Yes.

If so, what is the code, "me.requery"?
No, since Me would be a reference to the subform at this point. Also, there
would be no need to requery the entire form, just the control in question.
Also, where do I put the code?
I would try putting it in two places in the subform: Form_AfterUpdate and
Form_AfterDelConfirm. This way, the code should respond to new data, changes
in data, and deletions of records.

Option Compare Database
Option Explicit

Private Sub Form_AfterDelConfirm(Status As Integer)
Me.Parent.ListBoxName.Requery
End Sub

Private Sub Form_AfterUpdate()
Me.Parent.ListBoxName.Requery
End Sub


where "ListBoxName" is the name of your listbox control.


Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
__________________________________________
 
That did the trick. Thanks Tom.

Tom Wickerath said:
No, since Me would be a reference to the subform at this point. Also, there
would be no need to requery the entire form, just the control in question.

I would try putting it in two places in the subform: Form_AfterUpdate and
Form_AfterDelConfirm. This way, the code should respond to new data, changes
in data, and deletions of records.

Option Compare Database
Option Explicit

Private Sub Form_AfterDelConfirm(Status As Integer)
Me.Parent.ListBoxName.Requery
End Sub

Private Sub Form_AfterUpdate()
Me.Parent.ListBoxName.Requery
End Sub


where "ListBoxName" is the name of your listbox control.


Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
__________________________________________
 
Back
Top