Searching through a list box

  • Thread starter Thread starter Kaur
  • Start date Start date
K

Kaur

Hi,

I have developed an application in MS Access 2000 where I am trying to
highlight a record in the list box in form 2 based on the record
selected in form 1. The form 1 lists all the Document names and allows
me to add new documents. Form 2 has a list box that displays all the
document names. Clicking on a document in the list box shows me the
details of the selected document. I have over 100 documents in the list
box.
Basically what I am trying to do is from Form1 select a document and
open form 2 where the selected document in form 1 is highlighted in
form 2's document list box (without filtering the list box). This way
user does not have to search for the document he/she was on in form 1.

Any help would be appriciated.
 
Kaur said:
Hi,

I have developed an application in MS Access 2000 where I am trying to
highlight a record in the list box in form 2 based on the record
selected in form 1. The form 1 lists all the Document names and allows
me to add new documents. Form 2 has a list box that displays all the
document names. Clicking on a document in the list box shows me the
details of the selected document. I have over 100 documents in the list
box.
Basically what I am trying to do is from Form1 select a document and
open form 2 where the selected document in form 1 is highlighted in
form 2's document list box (without filtering the list box). This way
user does not have to search for the document he/she was on in form 1.

Any help would be appriciated.

Kaur,
This is actually a quite simple thing to do. I would start off by
creating a module with containing a global variable. ( if you dont
know how to declare a variable globally, simply go in the module and
enter this: Global GBL_Document as string )
Then on your first form, i am assuming you have a command button which
opens up to your second form so then in that command buttons 'Click'
event, right before it opens up the second form you need to define the
global variable GBL_Document.

GBL_Document=me.txtDocument 'this goes in your command
button click event

then you have just one thing left to do
in your second forms load event, paste the following code.

Private Sub Form_Load()
Dim x As Integer
For x = 0 To (List0.ListCount - 1)
If List0.ItemData(x) = GBL_Document Then
List0.Value = List0.ItemData(x)
End If
Next
End Sub

that is it, but obviously you have to alter the names of variables and
controls to fit your database, but this should work. let me know if
this does not work.

~Brian
 
Thanks ever so much. It works fine.


Kaur,
This is actually a quite simple thing to do. I would start off by
creating a module with containing a global variable. ( if you dont
know how to declare a variable globally, simply go in the module and
enter this: Global GBL_Document as string )
Then on your first form, i am assuming you have a command button which
opens up to your second form so then in that command buttons 'Click'
event, right before it opens up the second form you need to define the
global variable GBL_Document.

GBL_Document=me.txtDocument 'this goes in your command
button click event

then you have just one thing left to do
in your second forms load event, paste the following code.

Private Sub Form_Load()
Dim x As Integer
For x = 0 To (List0.ListCount - 1)
If List0.ItemData(x) = GBL_Document Then
List0.Value = List0.ItemData(x)
End If
Next
End Sub

that is it, but obviously you have to alter the names of variables and
controls to fit your database, but this should work. let me know if
this does not work.

~Brian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top