Results 1 to 8 of 8
  1. #1
    Join Date
    Apr 2003
    Posts
    280

    Unanswered: Listbox Index keep highlighting the first row

    I'm working on a listboy to display data/informatin in it. Well, I have got it to display it in the listbox by using customer access query. Well, in the listbox, it would show 7 columns(PatientSS, Month, DD, Year, Minutes, Units, Discipline) with data underneath it.

    My problem is when I click on the second data of the listbox, it would always highlight the first one but I click on the second, which the second one should be highlighted.

    <b>Here is the code that's put the data in the listbox.</b>

    Private Sub cmdCheckDate_Click()
    Dim conndb As ADODB.Connection
    Dim rsMinUnit As ADODB.Recordset
    Dim rsLastDay As ADODB.Recordset
    Dim strSQL As String

    Set conndb = CurrentProject.Connection
    Set rsMinUnit = New ADODB.Recordset
    Set rsLastDay = New ADODB.Recordset

    rsMinUnit.Open "MinUnitData", conndb, adOpenKeyset, adLockPessimistic, adCmdTable
    rsLastDay.Open "[qryLastofMonth]", conndb, adOpenKeyset, adLockPessimistic, adCmdTable

    lstDisplay.ColumnHeads = False
    lstDisplay.ColumnCount = 7
    lstDisplay.ColumnWidths = ".65in;.4in;.3in;.35in;.45in;.3in;4"
    lstDisplay.RowSourceType = "Table/Query"
    lstDisplay.RowSource = "qryLastofMonth"
    lstDisplay.Requery

    End Sub

    <b>ok, here is the listbox onclick code:</b>

    Private Sub lstDisplay_Click()

    lstDisplay.BoundColumn = 1
    txtSSN2.Value = lstDisplay.ItemData(lstDisplay.ListIndex)
    lstDisplay.Requery
    lstDisplay.BoundColumn = 2
    txtMonth.Value = lstDisplay.ItemData(lstDisplay.ListIndex)
    lstDisplay.Requery
    lstDisplay.BoundColumn = 3
    txtDay.Value = lstDisplay.ItemData(lstDisplay.ListIndex)
    lstDisplay.BoundColumn = 4
    txtYear.Value = lstDisplay.ItemData(lstDisplay.ListIndex)
    End Sub

    I noticed that I can't overwrite the listbox boundcolumn property. Do you tell think that is the cause of it. I can't see any other problem that would cause it.

    Thanks in advance.
    Last edited by lansing; 07-23-03 at 16:51.

  2. #2
    Join Date
    Apr 2003
    Posts
    280
    Well, I just find out the reason why it would cause this.

    For example:
    PatientID Month Day Year
    4444444 6 30 2003
    1323223 6 31 2003

    Imagine the data is in a list box. Ok, I want to bound to all foud column with this code:
    lstDisplay.BoundColumn = 1
    txtSSN2.Value = lstDisplay.ItemData(lstDisplay.ListIndex + 1)
    lstDisplay.Requery
    lstDisplay.BoundColumn = 2
    txtMonth.Value = lstDisplay.ItemData(lstDisplay.ListIndex + 1)
    lstDisplay.BoundColumn = 3
    txtDay.Value = lstDisplay.ItemData(lstDisplay.ListIndex + 1)
    lstDisplay.BoundColumn = 4
    txtYear.Value = lstDisplay.ItemData(lstDisplay.ListIndex + 1)

    If column 2 and column 4 has the same record as the previous, it always goes to the first one or the first record with the same data. That's why I'm confused why it would do that. Is there a to make the bound column to be distinct.

  3. #3
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    In qryLastOfMonth, the SQL should start with
    Select DISTINCT....

    That way, you won't get duplicate information...
    Inspiration Through Fermentation

  4. #4
    Join Date
    Apr 2003
    Posts
    280
    Well, the query has an Total as Group By, so there shouldn't be any duplicates. Anyways, I have got it to work.

    Dim RowSelected as integer

    RowSelected = lstDisplay.ListIndex '(<---just need this code)

    lstDisplay.BoundColumn = 1
    txtSSN2.Value = lstDisplay.ItemData(lstDisplay.ListIndex + 1)
    lstDisplay.BoundColumn = 2
    txtMonth.Value = lstDisplay.ItemData(lstDisplay.ListIndex + 1)
    lstDisplay.BoundColumn = 3
    txtDay.Value = lstDisplay.ItemData(lstDisplay.ListIndex + 1)
    lstDisplay.BoundColumn = 4
    txtYear.Value = lstDisplay.ItemData(lstDisplay.ListIndex + 1)

    lstDisplay.ListIndex = RowSelected '(<---and this code)

  5. #5
    Join Date
    Apr 2003
    Posts
    280
    Originally posted by lansing
    Well, the query has an Total as Group By, so there shouldn't be any duplicates. Anyways, I have got it to work.

    Dim RowSelected as integer

    RowSelected = lstDisplay.ListIndex '(<---just need this code)

    lstDisplay.BoundColumn = 1
    txtSSN2.Value = lstDisplay.ItemData(lstDisplay.ListIndex + 1)
    lstDisplay.BoundColumn = 2
    txtMonth.Value = lstDisplay.ItemData(lstDisplay.ListIndex + 1)
    lstDisplay.BoundColumn = 3
    txtDay.Value = lstDisplay.ItemData(lstDisplay.ListIndex + 1)
    lstDisplay.BoundColumn = 4
    txtYear.Value = lstDisplay.ItemData(lstDisplay.ListIndex + 1)

    lstDisplay.ListIndex = RowSelected '(<---and this code)

    Damn, I just find out with this code, I can't click on anything else. It's like everything is on LOCK but all of the obect lock properties is set to false. The only thing I can press is the listbox. What happening here?

  6. #6
    Join Date
    Apr 2003
    Posts
    280
    Anyone?

  7. #7
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    Here's a thought....
    Is the data behind the form an updatable recordset?
    If it's based on a query with aggregate functions, you shouldn't
    be able to change any of the bound data on the form.
    Inspiration Through Fermentation

  8. #8
    Join Date
    Apr 2003
    Posts
    280
    Well, I went ahead and work around it by connecting to the query itself but I still used the listbox just for data display.

    here is the code:
    Private Sub lstDisplay_Click()

    'Row click on the listbox
    RowSelected = lstDisplay.ListIndex

    rsqryLastofMonth.MoveFirst
    i = 0

    'Move to a specific record
    For i = 0 To RowSelected - 1
    rsqryLastofMonth.MoveNext
    i = i + 0
    Next i

    'display data
    txtSSN2 = rsqryLastofMonth("PatientID")
    txtMonth = rsqryLastofMonth("Month")
    txtDay = rsqryLastofMonth("Day")
    txtYear = rsqryLastofMonth("Year")
    end sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •