Solved

Select List Box Item From Variable

Posted on 2014-02-18
4
448 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

840 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