|
Access VBA Discuss using VBA for Access programming. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
June 20th, 2007, 02:15 PM
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
UNSelect Items in ListBox
Folks,
I am doing the usual population of listboxes on a form based on user selections before they launch to a new form. As they select items from option groups, a string is built to populate the first list box, which populates the second, and so on.
When the user goes back at any point and reselects an option, the list boxes disappear and the listbox rowsource is set to "". However, if they end up choosing the same thing (I am not sure of something else) the same selection they last made is still highlighted.
How do you UNSelect the listbox item? I have tried ListXX.Selected, ListXX.ItemSelected etc = "" or 0 etc. and I can't figure this one out.
I know this will be simple. Perhaps requery on the rowsource statement as well?
Thanks,
mmcdonal
__________________
mmcdonal
Look it up at: http://wrox.books24x7.com
|
June 21st, 2007, 07:19 AM
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
Well, after much fruitless research at Microsoft and MSDN, I stumbled upon the solution to this issue. Since I know my listboxes will never exceed more than about 50 records, if that, before I give them a new rowsource, I add this code.
Assume the list box was built, the user selected item 3, and then called the list box again, item 3 would still be selected. I put this in right before the rowsource code:
'--------------------------------------
Me.MyList1.RowSource = ""
Me.MyList1 = 99
Me.MyList1.RowSource = sSQL1
'--------------------------------------
Since the forced selection exceeds the number of values in the list, the list box doesn't know which one to select. When the new rowsource is added, it can't select the 99th item, so it resets itself... at least visually. I suppose I should put code in to build the next query string that checks for the value 99 and treats it as a non-selection. A small price to pay for getting the presentation right.
Thankfully, the list box doesn't throw an error when this value out of range is forced. There is no Limit To List property on list boxes, and I do not have a default value or validation rule. Setting the default value to 99 does not work.
Hope that helps.
mmcdonal
|
June 21st, 2007, 07:23 AM
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
When I say stumbled, I mean I got frustrated and just threw a high number at the list since setting the rowsource to nothing and requerying didn't work. I didn't find this anywhere in the literature.
I do know that the list box holds the value 99, so that must be accounted for in the next operation. I added MsgBox Me.MyList1.Value, and 99 popped up. So a selection has been made as far as the listbox is concerned.
mmcdonal
|
June 21st, 2007, 07:30 AM
|
Friend of Wrox
|
|
Join Date: Mar 2007
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
|
|
hi mmcdonal,
try "ListBox.Value = null", I have had the same issues, just be careful to ensure wherever the control is referenced you have your Nz()....
Best Regards,
Rob
|
June 21st, 2007, 07:42 AM
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
I did try the Null and Nothing and that didn't seem to work.
mmcdonal
|
June 21st, 2007, 08:01 AM
|
Friend of Wrox
|
|
Join Date: Mar 2007
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
|
|
strange...
I actually have it in my current project, and I set the value to "" and then update the recordset and all is cleared fine.. give that a whirl!
Rob
|
June 21st, 2007, 08:05 AM
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
I thought I had tried that too, but by golly it works. Where were you folks yesterday? =)
mmcdonal
|
June 21st, 2007, 08:09 AM
|
Friend of Wrox
|
|
Join Date: Mar 2007
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
|
|
apologies, kinda lost touch with this forum as I have been so busy working and studying, but trying to get more involved now :)
glad to hear it worked.
Best Regards,
Rob
|
|
|