How to automatically update the content of a list box after record

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

HI everyone,
I have a main form with a list box displaying contact info i.e, First
name,last name,address etc.... There is a button on that main form that opens
an other one to insert a new contact. I want the listbox on the main form to
show the most recent record inserted. I use the instruction:
forms!myMainForm!mylistOnMainForm.requery and it doesn't work. I used also
the instruction myMainForm.Refresh and it doesn't work either. Does anyone
know a way to achieve that?
thanks
 
Zadi

After inserting the record, you need to select and then set your listbox's
listindex property to the correct entry. I've got some sample code lying
around that I use when I need to perform such an operation. Try the following:

Dim i As Integer
mylistOnMainForm.SetFocus
For i = 0 To mylistOnMainForm.ListCount - 1
If mylistOnMainForm.ItemData(i) = (ID of record you inserted) Then
mylistOnMainForm.Selected(i) = True
mylistOnMainForm.ListIndex = i
Exit For
End If
Next i

Note that I'm assuming you set the listbox up with an ID field for each
entry, and that the ID will be for whatever field is the bound column. If
this isn't the case then the code above probably won't work. Reply with the
RowSource, ColumnCount, ColumnWidth and BoundColumn properties of the listbox
and I'll give it another try. Also let me know what the key field is for the
record you are inserting.
 
Back
Top