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 sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listbox item ... "clicked or selected" 1

Status
Not open for further replies.

sabavno

Programmer
Jul 25, 2002
381
CA
Hi

I have a question. In my listbox, when user manually clicks on the record and then clicks on the button "View Record" everything works fine, but when I use code to select a row in the listbox (List0.Selected(intRow) = True) then the button "View Record" does not work, because it does not recognize the listitem.

Please advise
 
The problem is that setting the list item to selected in code does not set the list to that item, it just marks it as selected.

If you do something like

In the on click event on your list box type

msgbox <listname>.ListIndex

You will see that each time you click on the list box the index is set to the clicked item.

However if you do on say a command button.

<listname>.Selected(3) = True
msgbox <listname>.ListIndex

You will always get -1

If you use

<listname>.ItemData(3)

You will get the value of the bound column of list item index 3 (which is what you need).
I'm not sure how you can implement this as I don't know the rest of your code.

Hope this is of some help.

 
Thanks

The thing is I have a FIND routine that when finds a record makes it selected, but I need to make it 'clicked'

Here is what I have

Private Sub cmdFind_Click()



Dim intRow As Integer
Dim cntl As Control
Dim rst As DAO.Recordset
Dim sql As String
Dim varA As String


varA = Nz(InputBox(&quot;Enter PIN&quot;, &quot;Cancel&quot;))






Set cntl = Me!List0

sql = &quot;Select PIN from BlackBerryRecord Where PIN = &quot; & varA




Set rst = CurrentDb.OpenRecordset(sql, dbOpenDynaset)
If rst.NoMatch = False Then
rst.MoveFirst
For intRow = 0 To cntl.ListCount - 1
If List0.Column(1, intRow) = varA Then
List0.selected (intRow) = true


Exit For
End If
Next intRow
End If

Set rst = Nothing

End Sub


Please help me with this.

I need the found row gets the status of clicked rather than simply selected!
 
Thanks

The thing is I have a FIND routine that when finds a record makes it selected, but I need to make it 'clicked'

Here is what I have

Private Sub cmdFind_Click()



Dim intRow As Integer
Dim cntl As Control
Dim rst As DAO.Recordset
Dim sql As String
Dim varA As String


varA = Nz(InputBox(&quot;Enter PIN&quot;, &quot;Cancel&quot;))






Set cntl = Me!List0

sql = &quot;Select PIN from BlackBerryRecord Where PIN = &quot; & varA




Set rst = CurrentDb.OpenRecordset(sql, dbOpenDynaset)
If rst.NoMatch = False Then
rst.MoveFirst
For intRow = 0 To cntl.ListCount - 1
If List0.Column(1, intRow) = varA Then
List0.selected (intRow) = true


Exit For
End If
Next intRow
End If

Set rst = Nothing

End Sub


Please help me with this.

I need the found row to get the status of clicked rather than simply selected!
 
From what I can see the above code finds a record and marks the relating list entry as selected. Can you show me the code you want to next in the 'click' bit...
 
Once the FIND routine finds a row, user then clicks on &quot;VIEW RECORD&quot; button to open another form

This is code for VIEW RECORD button

Private Sub cmdViewRecord_Click()


Dim stDocName As String
Dim stLinkCriteria As String
Dim intColumn As Integer




stDocName = &quot;ViewBb&quot;
If List0.ListIndex < 0 Then
MsgBox &quot;Please select the record&quot;
Else
stLinkCriteria = &quot;[RecordID]=&quot; & Me![List0]
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If

End Sub

The thing is FIND routine makes a row selected but not clicked which causes RecordID in the criteria be equal to null.
 
I would make the view record a separate sub and call it from both places passing the value to search for.

ie.


Private Sub mViewRecord(byval vlngRecordID as Long)
Dim stDocName As String
Dim stLinkCriteria As String
Dim intColumn As Integer

stDocName = &quot;ViewBb&quot;

stLinkCriteria = &quot;[RecordID]=&quot; & vlngRecordID DoCmd.OpenForm stDocName, , , stLinkCriteria


End Sub


Private Sub List0_Click()
if list0.listindex > -1 then
mViewRecord (List0.ItemData(List0.ItemsSelected(0)))
else
msgbox &quot;Please Select Record&quot;
end if
End Sub

and in commandFind_Click after

List0.selected (intRow) = true
mViewRecord (List0.ItemData(List0.ItemsSelected(0)))
 
Well,
It worked find, thanks a lot

But if I don't want to view it automatically. I want to open form on the click event
 
Well,
Sorry I just figured it out

Thanks a lot!!!
You have no idea how much you helped me
I appreciate that!

Good luck
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top