Hi everyone,
I built a listbox from an Access table, I have a button to edit the record.
However, when I try to find the record in table associated with the listbox
string, I can't. I am NOT getting any error, but I am not locating the correct record. In fact I am getting a weird key value from the table, like 89434324.
Your help is most appreciated.


void CDataSrce::OnEditDatasource()
{
CSourceTable Tbl;
char buf[200];

CDSEntry DSEntry; // add/edit dialog
DSEntry.bEdit = TRUE;

// Get the currently selected listbox index and associated ID
int iIndex = m_clDataSourceListBox.GetCurSel();
int iSourceId = m_clDataSourceListBox.GetItemData(iIndex);

//Find the record in the table, based on SourceID
wsprintf(buf, "select * from Source where SourceID=%d", iSourceId);
if (!Tbl.OpenTable(dbOpenDynaset, buf))
{
AfxMessageBox(Tbl.ErrorMsg());
return;
}

if (Tbl.NoRecords())
{
AfxMessageBox("Error: No Record in Source");
Tbl.Close();
return;
}


// Set the dialog record to be that record
DSEntry.Rec = Tbl.m_Rec;
DSEntry.iSourceIndex = iIndex;

Tbl.Close();

if (DSEntry.DoModal() == IDOK)
{
// refresh the listbox
FillSourceList(m_clDataSourceListBox);
m_clDataSourceListBox.SetCurSel(iIndex); // go back to selected item
}
}