Moving to position of multi select listbox










0















I have a multi select listbox, which I would like to make searchable. If the searched for value is found in the listbox, I'd like to scroll to that position, but not select it. Is this possible? The code I have so far for searching is :-



With lstComm
For i = 0 To .ListCount - 1
If .Column(6, i) = txtSearch.Value Then

End If
Next i
End With


...but I'm not sure how to complete the scroll.










share|improve this question



















  • 1





    Access doesn't offer a built-in way to scroll list boxes. I can write up a WinAPI answer if you're interested, but it will be rather complicated since Access doesn't offer a built-in way to get the hWnd for a form control.

    – Erik A
    Nov 14 '18 at 11:34















0















I have a multi select listbox, which I would like to make searchable. If the searched for value is found in the listbox, I'd like to scroll to that position, but not select it. Is this possible? The code I have so far for searching is :-



With lstComm
For i = 0 To .ListCount - 1
If .Column(6, i) = txtSearch.Value Then

End If
Next i
End With


...but I'm not sure how to complete the scroll.










share|improve this question



















  • 1





    Access doesn't offer a built-in way to scroll list boxes. I can write up a WinAPI answer if you're interested, but it will be rather complicated since Access doesn't offer a built-in way to get the hWnd for a form control.

    – Erik A
    Nov 14 '18 at 11:34













0












0








0








I have a multi select listbox, which I would like to make searchable. If the searched for value is found in the listbox, I'd like to scroll to that position, but not select it. Is this possible? The code I have so far for searching is :-



With lstComm
For i = 0 To .ListCount - 1
If .Column(6, i) = txtSearch.Value Then

End If
Next i
End With


...but I'm not sure how to complete the scroll.










share|improve this question
















I have a multi select listbox, which I would like to make searchable. If the searched for value is found in the listbox, I'd like to scroll to that position, but not select it. Is this possible? The code I have so far for searching is :-



With lstComm
For i = 0 To .ListCount - 1
If .Column(6, i) = txtSearch.Value Then

End If
Next i
End With


...but I'm not sure how to complete the scroll.







vba ms-access access-vba






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 11:23







user1936588

















asked Nov 14 '18 at 11:12









user1936588user1936588

483514




483514







  • 1





    Access doesn't offer a built-in way to scroll list boxes. I can write up a WinAPI answer if you're interested, but it will be rather complicated since Access doesn't offer a built-in way to get the hWnd for a form control.

    – Erik A
    Nov 14 '18 at 11:34












  • 1





    Access doesn't offer a built-in way to scroll list boxes. I can write up a WinAPI answer if you're interested, but it will be rather complicated since Access doesn't offer a built-in way to get the hWnd for a form control.

    – Erik A
    Nov 14 '18 at 11:34







1




1





Access doesn't offer a built-in way to scroll list boxes. I can write up a WinAPI answer if you're interested, but it will be rather complicated since Access doesn't offer a built-in way to get the hWnd for a form control.

– Erik A
Nov 14 '18 at 11:34





Access doesn't offer a built-in way to scroll list boxes. I can write up a WinAPI answer if you're interested, but it will be rather complicated since Access doesn't offer a built-in way to get the hWnd for a form control.

– Erik A
Nov 14 '18 at 11:34












1 Answer
1






active

oldest

votes


















1














This should work fine:



Dim index As Long
With lstComm
Dim match As Boolean
For index = 0 To .ListCount - 1
If .Column(1, index) = txtSearch.Value Then
match = True
Exit For
End If
Next

If Not match Then Exit Sub

Dim isSelected As Boolean
isSelected = .Selected(index)

.Selected(index) = True
.Selected(index) = isSelected
End With


It retrieves the searched item of the listbox.



If no item has been found it exists.



Otherwise it stores the current selection state of that item, selects it to position the listbox, and restores the stored state of the item.






share|improve this answer























  • Selecting and unselecting an item in a listbox does just that, nothing else. It doesn't scroll to the item being selected (for me on Access 2016 using a multi-select list box, at least)

    – Erik A
    Nov 14 '18 at 12:07












  • I've tested that before, of course. It scrolled correctly to the position. Works with listbox controls Multi Select set to Simple and Extended. Microsoft Access 2013.

    – Unhandled Exception
    Nov 14 '18 at 12:14












  • On the listbox I'm using (Access 2016 (Office 365), when a row is selected, it's position is being scrolled to.

    – user1936588
    Nov 14 '18 at 12:14






  • 1





    Well, the only thing I can say is that this is undocumented behavior and just doesn't work for me (Build 9126). Your mileage may vary, apparently. If you're going to deploy it, I'd do extensive testing beforehand.

    – Erik A
    Nov 14 '18 at 12:22










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53298879%2fmoving-to-position-of-multi-select-listbox%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














This should work fine:



Dim index As Long
With lstComm
Dim match As Boolean
For index = 0 To .ListCount - 1
If .Column(1, index) = txtSearch.Value Then
match = True
Exit For
End If
Next

If Not match Then Exit Sub

Dim isSelected As Boolean
isSelected = .Selected(index)

.Selected(index) = True
.Selected(index) = isSelected
End With


It retrieves the searched item of the listbox.



If no item has been found it exists.



Otherwise it stores the current selection state of that item, selects it to position the listbox, and restores the stored state of the item.






share|improve this answer























  • Selecting and unselecting an item in a listbox does just that, nothing else. It doesn't scroll to the item being selected (for me on Access 2016 using a multi-select list box, at least)

    – Erik A
    Nov 14 '18 at 12:07












  • I've tested that before, of course. It scrolled correctly to the position. Works with listbox controls Multi Select set to Simple and Extended. Microsoft Access 2013.

    – Unhandled Exception
    Nov 14 '18 at 12:14












  • On the listbox I'm using (Access 2016 (Office 365), when a row is selected, it's position is being scrolled to.

    – user1936588
    Nov 14 '18 at 12:14






  • 1





    Well, the only thing I can say is that this is undocumented behavior and just doesn't work for me (Build 9126). Your mileage may vary, apparently. If you're going to deploy it, I'd do extensive testing beforehand.

    – Erik A
    Nov 14 '18 at 12:22















1














This should work fine:



Dim index As Long
With lstComm
Dim match As Boolean
For index = 0 To .ListCount - 1
If .Column(1, index) = txtSearch.Value Then
match = True
Exit For
End If
Next

If Not match Then Exit Sub

Dim isSelected As Boolean
isSelected = .Selected(index)

.Selected(index) = True
.Selected(index) = isSelected
End With


It retrieves the searched item of the listbox.



If no item has been found it exists.



Otherwise it stores the current selection state of that item, selects it to position the listbox, and restores the stored state of the item.






share|improve this answer























  • Selecting and unselecting an item in a listbox does just that, nothing else. It doesn't scroll to the item being selected (for me on Access 2016 using a multi-select list box, at least)

    – Erik A
    Nov 14 '18 at 12:07












  • I've tested that before, of course. It scrolled correctly to the position. Works with listbox controls Multi Select set to Simple and Extended. Microsoft Access 2013.

    – Unhandled Exception
    Nov 14 '18 at 12:14












  • On the listbox I'm using (Access 2016 (Office 365), when a row is selected, it's position is being scrolled to.

    – user1936588
    Nov 14 '18 at 12:14






  • 1





    Well, the only thing I can say is that this is undocumented behavior and just doesn't work for me (Build 9126). Your mileage may vary, apparently. If you're going to deploy it, I'd do extensive testing beforehand.

    – Erik A
    Nov 14 '18 at 12:22













1












1








1







This should work fine:



Dim index As Long
With lstComm
Dim match As Boolean
For index = 0 To .ListCount - 1
If .Column(1, index) = txtSearch.Value Then
match = True
Exit For
End If
Next

If Not match Then Exit Sub

Dim isSelected As Boolean
isSelected = .Selected(index)

.Selected(index) = True
.Selected(index) = isSelected
End With


It retrieves the searched item of the listbox.



If no item has been found it exists.



Otherwise it stores the current selection state of that item, selects it to position the listbox, and restores the stored state of the item.






share|improve this answer













This should work fine:



Dim index As Long
With lstComm
Dim match As Boolean
For index = 0 To .ListCount - 1
If .Column(1, index) = txtSearch.Value Then
match = True
Exit For
End If
Next

If Not match Then Exit Sub

Dim isSelected As Boolean
isSelected = .Selected(index)

.Selected(index) = True
.Selected(index) = isSelected
End With


It retrieves the searched item of the listbox.



If no item has been found it exists.



Otherwise it stores the current selection state of that item, selects it to position the listbox, and restores the stored state of the item.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 14 '18 at 11:59









Unhandled ExceptionUnhandled Exception

1,2452510




1,2452510












  • Selecting and unselecting an item in a listbox does just that, nothing else. It doesn't scroll to the item being selected (for me on Access 2016 using a multi-select list box, at least)

    – Erik A
    Nov 14 '18 at 12:07












  • I've tested that before, of course. It scrolled correctly to the position. Works with listbox controls Multi Select set to Simple and Extended. Microsoft Access 2013.

    – Unhandled Exception
    Nov 14 '18 at 12:14












  • On the listbox I'm using (Access 2016 (Office 365), when a row is selected, it's position is being scrolled to.

    – user1936588
    Nov 14 '18 at 12:14






  • 1





    Well, the only thing I can say is that this is undocumented behavior and just doesn't work for me (Build 9126). Your mileage may vary, apparently. If you're going to deploy it, I'd do extensive testing beforehand.

    – Erik A
    Nov 14 '18 at 12:22

















  • Selecting and unselecting an item in a listbox does just that, nothing else. It doesn't scroll to the item being selected (for me on Access 2016 using a multi-select list box, at least)

    – Erik A
    Nov 14 '18 at 12:07












  • I've tested that before, of course. It scrolled correctly to the position. Works with listbox controls Multi Select set to Simple and Extended. Microsoft Access 2013.

    – Unhandled Exception
    Nov 14 '18 at 12:14












  • On the listbox I'm using (Access 2016 (Office 365), when a row is selected, it's position is being scrolled to.

    – user1936588
    Nov 14 '18 at 12:14






  • 1





    Well, the only thing I can say is that this is undocumented behavior and just doesn't work for me (Build 9126). Your mileage may vary, apparently. If you're going to deploy it, I'd do extensive testing beforehand.

    – Erik A
    Nov 14 '18 at 12:22
















Selecting and unselecting an item in a listbox does just that, nothing else. It doesn't scroll to the item being selected (for me on Access 2016 using a multi-select list box, at least)

– Erik A
Nov 14 '18 at 12:07






Selecting and unselecting an item in a listbox does just that, nothing else. It doesn't scroll to the item being selected (for me on Access 2016 using a multi-select list box, at least)

– Erik A
Nov 14 '18 at 12:07














I've tested that before, of course. It scrolled correctly to the position. Works with listbox controls Multi Select set to Simple and Extended. Microsoft Access 2013.

– Unhandled Exception
Nov 14 '18 at 12:14






I've tested that before, of course. It scrolled correctly to the position. Works with listbox controls Multi Select set to Simple and Extended. Microsoft Access 2013.

– Unhandled Exception
Nov 14 '18 at 12:14














On the listbox I'm using (Access 2016 (Office 365), when a row is selected, it's position is being scrolled to.

– user1936588
Nov 14 '18 at 12:14





On the listbox I'm using (Access 2016 (Office 365), when a row is selected, it's position is being scrolled to.

– user1936588
Nov 14 '18 at 12:14




1




1





Well, the only thing I can say is that this is undocumented behavior and just doesn't work for me (Build 9126). Your mileage may vary, apparently. If you're going to deploy it, I'd do extensive testing beforehand.

– Erik A
Nov 14 '18 at 12:22





Well, the only thing I can say is that this is undocumented behavior and just doesn't work for me (Build 9126). Your mileage may vary, apparently. If you're going to deploy it, I'd do extensive testing beforehand.

– Erik A
Nov 14 '18 at 12:22



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53298879%2fmoving-to-position-of-multi-select-listbox%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

Museum of Modern and Contemporary Art of Trento and Rovereto