Solved

Select List Box Item From Variable

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

Accepted Solution

by:
Rey Obrero 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
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 …
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

757 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now