unbound listbox... how do i make the current record selected

  • Thread starter Thread starter dannie
  • Start date Start date
D

dannie

I have a listbox that displays the name of all the records, as I use the
navigation buttons to go through different records my listbox does not update
what it has selected.

My listbox is unbound and here are some things you might want to know:

Row Source:
SELECT InspectionsDI.ID, InspectionsDI.[Manhole Number] FROM [InspectionsDI
Query];

Private Sub lstDI_AfterUpdate()
DoCmd.GoToRecord acDataForm, "DropInletForm", acGoTo, lstDI.ListIndex + 1
End Sub

Thanks for help
 
dannie said:
I have a listbox that displays the name of all the records, as I use the
navigation buttons to go through different records my listbox does not
update
what it has selected.

My listbox is unbound and here are some things you might want to know:

Row Source:
SELECT InspectionsDI.ID, InspectionsDI.[Manhole Number] FROM
[InspectionsDI
Query];

Private Sub lstDI_AfterUpdate()
DoCmd.GoToRecord acDataForm, "DropInletForm", acGoTo, lstDI.ListIndex + 1
End Sub

Thanks for help


Is it that you want the list box to automatically show as selected the
record that is current? If the bound column of the list box is the first
column (the ID field), then you might use this code in the form's Current
event:

'------ start of code ------
Private Sub Form_Current()

Me.lstDI = Me!ID

End Sub
'------ end of code ------
 
dannie said:
I have a listbox that displays the name of all the records, as I use the
navigation buttons to go through different records my listbox does not
update
what it has selected.

My listbox is unbound and here are some things you might want to know:

Row Source:
SELECT InspectionsDI.ID, InspectionsDI.[Manhole Number] FROM
[InspectionsDI
Query];

Private Sub lstDI_AfterUpdate()
DoCmd.GoToRecord acDataForm, "DropInletForm", acGoTo, lstDI.ListIndex + 1
End Sub

Thanks for help


Incidentally, I would probably do this somewhat differently, so that I would
have an option to sort the list box or the form differently:

Private Sub lstDI_AfterUpdate()

With Me.lstDI
If Not IsNull(.Value) Then
Me.Recordset.FindFirst "ID = " & .Value
End If
End With

End Sub

By making the navgation data-based, rather than sequence-based, you avoid
having problems if the list box and form aren't sorted the same way.
 
I tested that out and it worked great, now I need to figure out how to do it
from my code module because my OnCurrent event has a function name which
calls a function from a module. I dont know how to have it call that
function and do a event procedure.

Dirk Goldgar said:
dannie said:
I have a listbox that displays the name of all the records, as I use the
navigation buttons to go through different records my listbox does not
update
what it has selected.

My listbox is unbound and here are some things you might want to know:

Row Source:
SELECT InspectionsDI.ID, InspectionsDI.[Manhole Number] FROM
[InspectionsDI
Query];

Private Sub lstDI_AfterUpdate()
DoCmd.GoToRecord acDataForm, "DropInletForm", acGoTo, lstDI.ListIndex + 1
End Sub

Thanks for help


Is it that you want the list box to automatically show as selected the
record that is current? If the bound column of the list box is the first
column (the ID field), then you might use this code in the form's Current
event:

'------ start of code ------
Private Sub Form_Current()

Me.lstDI = Me!ID

End Sub
'------ end of code ------


--
Dirk Goldgar, MS Access MVP
Access tips: www.datagnostics.com/tips.html

(please reply to the newsgroup)
 
dannie said:
I tested that out and it worked great, now I need to figure out how to do
it
from my code module because my OnCurrent event has a function name which
calls a function from a module. I dont know how to have it call that
function and do a event procedure.

Call the function from the event procedure, before or after new code for the
event. For example:

'------ start of code ------
Private Sub Form_Current()

Me.lstDI = Me!ID

Call YourFunction()

End Sub
'------ end of code ------
 
Back
Top