Listbox and setting Listindex

  • Thread starter Thread starter PC
  • Start date Start date
P

PC

I cannot seem to get setting listindex correctly.

I have a listbox that, when a user double clicks on it, it
opens up the respective form which allows the user to
input data.

I have a button located adjacent to the listbox
which "adds" a new entry to the listbox with some preset
data. When the user double clicks on an entry in the
listbox, it opens the form with that data in tow.

That double-click action for the listbox looks like this,

DoCmd.OpenForm "frmScreen_Logs",
acNormal, , "Screen_Log_ID=" & lstScreen_Logs.Value

What I want to do now is when the user clicks on the ADD
button, it inserts the same preset data but then opens the
form directly. This will reduce the action from 2 steps to
one step.

Thanks,
PC
 
itemSelected= .ItemData(itemSelected)
should have been
itemSelected= .ItemData(listItem )
-----Original Message-----
PC,

You need to loop through each item in the listbox to
determine which one is selected. The following would do
that:

dim listItem as variant
dim itemSelected as variant

With Me![yourListbox]

For listItem = 0 To .ListCount - 1
If (.selected(listItem )) Then

itemSelected= .ItemData(itemSelected)
...Do what you want with the itemSelected

End If

Next listItem

End With
-----Original Message-----
I cannot seem to get setting listindex correctly.

I have a listbox that, when a user double clicks on it, it
opens up the respective form which allows the user to
input data.

I have a button located adjacent to the listbox
which "adds" a new entry to the listbox with some preset
data. When the user double clicks on an entry in the
listbox, it opens the form with that data in tow.

That double-click action for the listbox looks like this,

DoCmd.OpenForm "frmScreen_Logs",
acNormal, , "Screen_Log_ID=" & lstScreen_Logs.Value

What I want to do now is when the user clicks on the ADD
button, it inserts the same preset data but then opens the
form directly. This will reduce the action from 2 steps to
one step.

Thanks,
PC
.
.
 
Back
Top