I'm not quite sure what you are doing based on your post. It knid of looks
like you are directly referencing the IS number of the record you are adding
and that won't work because you cannot garrantee that they will always
correlate. This is how I repopulate my list box when I add somehting new to
it.
CRecSet.MoveFirst
For i = 1 To CRecSet.RecordCount
'fMainForm.lstCfgName.AddItem (CRecSet.Fields(1))
cboCFGName.AddItem CRecSet.Fields(1)
CRecSet.MoveNext
Next
Hope this helps,
Chris Stamey
------------------
http://www.Farther.com/VBAnswerNetwork
Quote:
>It sounds like you may not be either saving the record at the
>appropriate time (do you have a specific button to do so, or trapping
>entry back into the listbox?),
I did check by open the VisData to monitor when exactly the record is added
into the database. I found that after the following code, new record with
new Cus_ID (primary index field) had been added. Any idea??
=================================================
Dim r as Recordset
[.....]
r.AddNew
r.Fields("Name") = Text1.text
[.....]
r.Update '<<~ New record with new Cus_ID is added after this line
r.MoveLast '<<~ Is this one causing the problem? But without this will
cause error when
' adding List1.ItemData(List1.NewIndex) =
r.Fields("Cus_ID")
List1.AddItem Text1.text
List1.ItemData(List1.NewIndex) = r.Fields("Cus_ID") 'Add the new Cus_ID
into the listbox
List1.ListIndex = List1.NewIndex ' This will set focus to the
name just added,
' but
the wrong Cus_ID cause different info
' is
being displayed.
Debug.Print "New Cus_ID is : ", List1.ItemData(List1.NewIndex) ' But found
the Cus_ID is not new!!
=================================================
Quote:
>or you may need to requery the listbox, to force it to go back, re-read its
recordset
>and pick up the new record.
I do this at first and found no problem. However I dislike the annoying
effect when adding/deleting the record, the listbox will Refresh and re-read
the recordset. If there are few thousand names to be display, then reload
the entire name will seem slow don't you think?? Please correct me if I'm
wrong.
Thank you very much.