Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Select List Box Item From Variable

Posted on 2014-02-18
4
Medium Priority
?
465 Views
Last Modified: 2014-02-18
I am opening a form from another form. The form being opened has a list box in it, with the Primary Key of the records in that list box in the first column, with has zero width.

The OpenArgs of the opened form may have a value in it identifying which row of the list box to select. How do I use that value to select the desired item in the list box, just as if the user had clicked on the row. I don't think I can simply count down to the desired record, as I don't know what the "Index" would be for the one I want.

Thanks.
0
Comment
Question by:Buck_Beasom
  • 2
4 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 total points
ID: 39867357
you can iterate thru the list in the listbox,

dim j
with me.list0
   for j=0 to .listcount-1
        if .column(1,j)=me.openargs then
           .selected(j)=true
            exit for
        end if
   next
end with

off course this must be tweak to suit the setting of your listbox, rowsource etc..

post more info on how you will use the selected item.
0
 
LVL 49

Expert Comment

by:Dale Fye
ID: 39867445
I don't think you need the loop, unless the value you are passing is not in the bound column.

You should be able to use the Form_Load event, something like:

Private Sub Form_Load

    if isNull(me.openargs) = False then
        me.YourListName = Val(me.openargs)
    endif

End Sub
0
 

Author Closing Comment

by:Buck_Beasom
ID: 39867682
This worked, although I had to change the 1 to a 0 as it is the first column that is bound.

Thanks!
0
 
LVL 49

Expert Comment

by:Dale Fye
ID: 39867726
Did you try the simpler version?
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question