Solved

Select List Box Item From Variable

Posted on 2014-02-18
4
451 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 500 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 47

Expert Comment

by:Dale Fye (Access MVP)
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 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 39867726
Did you try the simpler version?
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

679 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