Solved

Select List Box Item From Variable

Posted on 2014-02-18
4
455 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 48

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 48

Expert Comment

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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

623 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