Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change List Box Selected Value to New Record

Status
Not open for further replies.

CGSB

Programmer
May 23, 2006
35
CA
I have a list box which displays "file_no" from a table.

My module requeries the list box after a new record has been added to the table.

I would like the new record's "file_no" to be selected after the list box is requeried.

Please let me know if this is unclear, I'm not sure if I'm explaining this right.

Thanks!
 
whatever the bound column, on your list box is,
make it equal the same value of the new record.

If it is the pkID, then maybe

Me.lstbox.Requery
Me.listBox.Value = DMax("pkID","tblNewRecord")

Or
depending on how you have your lstBox sorted,
you can use the, lstBox.selected(9) = True

If the new record, is at the top of your list then
lstBox.selected(0) = True
If at the bottom, then,
lstBox.selected(lstBox.ListCount - 1) = True

 
How are ya CGSB . . .

The trick here is how to get [blue]file_no[/blue] after a record is saved and before the listbox is requeried! If you can accomplish this store [blue]file_no[/blue] in a variable then:
Code:
[blue]   Dim db As DAO.Database, rst As DAO.Recordset, [purple][b]Variable[/b][/purple]
   
   Variable = [file_no]
   Me![b]ListboxName[/b].RowSource = Me![b]ListboxName[/b].RowSource [green]'listbox requery![/green]
   
   Set db = CurrentDb
   Set rst = db.OpenRecordset(Me![b]ListboxName[/b].RowSource, dbOpenDynaset)
   rst.FindFirst "[[purple][b]FieldName[/b][/purple]] = '" & [purple][b]Variable[/b][/purple] & "'"
   
   If Not rst.NoMatch Then
      Me![b]ListboxName[/b].Selected(rst.AbsolutePosition) = True
   End If
   
   Set rst = Nothing
   Set db = Nothing[/blue]

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top