Results 1 to 7 of 7
  1. #1
    jackkent is offline Novice
    Windows Vista Access 2007
    Join Date
    Sep 2010
    Posts
    12

    Rescrolling in ListBox on Double Click


    When double clicking on a record in a ListBox the contents of the box scrolls (i.e. I d/click on a record that may be several pages down the list and the listbox scrolls back to the top). This is very annoying.

    Working in Access 2007.

    Would very much appreciate a solution to this issue.

  2. #2
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    702
    Are you running a refresh or requery on the list box?

  3. #3
    jackkent is offline Novice
    Windows Vista Access 2007
    Join Date
    Sep 2010
    Posts
    12

    Access

    HiTechCoach,
    Thanks for your prompt reply... Hmmmmm, I guess neither. I'm an amateur at this but am a do it or die trying guy. This is my DoubleClick event:

    Private Sub lst_kanji_DblClick(Cancel As Integer)

    Dim str_item As Variant
    Dim wrk As DAO.Workspace
    Dim db As DAO.Database

    If Me.lst_kanji.ItemsSelected.count = 0 Then Exit Sub

    'Get the data from the DoubleClicked on row.
    '
    For Each str_item In Me.lst_kanji.ItemsSelected
    Me.txt_core_meaning.Value = Me.lst_kanji.Column(0, str_item)
    Me.txt_romaji.Value = Me.lst_kanji.Column(4, str_item)
    Me.Txt_pos.Value = Me.lst_kanji.Column(6, str_item)
    Me.txt_tagged.Value = Me.lst_kanji.Column(7, str_item)
    Next str_item

    Set wrk = DBEngine(0)
    Set db = CurrentDb

    'If the record is tagged, set it to "" (untagged).
    '
    If Me.txt_tagged.Value = "yes" Then

    wrk.BeginTrans

    db.Execute "UPDATE tbl_kanji SET tagged = '' WHERE core_meaning = '" & txt_core_meaning.Value & "' AND " & _
    "romaji = '" & txt_romaji.Value & "' AND pos = '" & Txt_pos.Value & "'"

    wrk.CommitTrans
    wrk.Close

    'If the record is not tagged, set the tagged value to "yes".
    '
    ElseIf Me.txt_tagged.Value = "" Then

    wrk.BeginTrans

    db.Execute "UPDATE tbl_kanji SET tagged = 'yes' WHERE core_meaning = '" & txt_core_meaning.Value & "' AND " & _
    "romaji = '" & txt_romaji.Value & "' AND pos = '" & Txt_pos.Value & "'"

    wrk.CommitTrans
    wrk.Close

    End If
    'Reretrieve the data into the list box.
    '
    Me.lst_kanji.RowSourceType = "Table/Query"
    Me.lst_kanji.RowSource = "SELECT core_meaning, kanji, Right(Space(7) & strokes, 7), on_kun_yomi, romaji, " & _
    "Right(Space(11) & frequency, 11), pos, tagged FROM tbl_kanji"

    Call tag_count

    End Sub

  4. #4
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    702
    This code is probably the cause:

    Code:
    Me.lst_kanji.RowSourceType = "Table/Query"
        Me.lst_kanji.RowSource = "SELECT core_meaning, kanji, Right(Space(7) & strokes, 7), on_kun_yomi, romaji, " & _
        "Right(Space(11) & frequency, 11), pos, tagged FROM tbl_kanji"
    Resetting the row source property of list box is very similar to requerying a list box.

    Before you run the above code you will need to save the the current selection(s). After the above code runs you will then need to run VBA code to reselect the items if they exist in the new row source.

    Boyd Trimmell aka Hitechcoach
    Microsoft Access MVP
    Started with Access 2.0. Now using the latest version of Access.
    Last edited by HiTechCoach; 09-28-2010 at 01:28 PM.

  5. #5
    jackkent is offline Novice
    Windows Vista Access 2007
    Join Date
    Sep 2010
    Posts
    12
    Sorry but not sure I understand... Do you mean to save the data to a RecordSet first, run my code, and then requery from the recordset?

  6. #6
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    702
    Quote Originally Posted by jackkent View Post
    Sorry but not sure I understand... Do you mean to save the data to a RecordSet first, run my code, and then requery from the recordset?
    Not exactly.

    To reposition the List box after a requery you must store the selected item. After the require you will have to use VBA code to reselect the item in the list box. This should reposition the list box just like if you did it manually.

    This might help: The idea is similar to saving a bookmark in a recordset.

    Boyd Trimmell aka Hitechcoach
    Microsoft Access MVP
    Started with Access 2.0. Now using the latest version of Access.
    Last edited by HiTechCoach; 09-28-2010 at 01:28 PM.

  7. #7
    jackkent is offline Novice
    Windows Vista Access 2007
    Join Date
    Sep 2010
    Posts
    12
    Thank you. Will try this.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Currency Vs Double
    By Mclaren in forum Database Design
    Replies: 1
    Last Post: 08-12-2010, 05:38 PM
  2. switching int/double
    By giladweil in forum Access
    Replies: 2
    Last Post: 07-05-2010, 01:13 AM
  3. Append query double criteria
    By Gerry in forum Queries
    Replies: 0
    Last Post: 03-23-2010, 03:55 PM
  4. OpenReport Command with Double Check Where Statement
    By Robert M in forum Programming
    Replies: 3
    Last Post: 09-17-2009, 04:01 PM
  5. double booked entries
    By qbc in forum Access
    Replies: 3
    Last Post: 08-28-2009, 10:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums