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

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?
 
T

Tom Wickerath

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/
__________________________________________
 
G

gagecres

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/
__________________________________________
 

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