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

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
 
D

Dirk Goldgar

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 ------
 
D

Dirk Goldgar

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.
 
D

dannie

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)
 
D

Dirk Goldgar

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 ------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top