Listbox table not talking. Need help

  • Thread starter Daama via AccessMonster.com
  • Start date
D

Daama via AccessMonster.com

Hi,

I need some help!!!!

Maybe I am trying to do multiple gings at one with this procedure. But I'm
sort of lost!!!

I have a list box displaying several items. The same items are also found in
a separate table named: "FieldDescription". In this table, there are 2 column:
one listing those items and the other column contains the description of each
item> What I want to do is create an OnClick event that checks if the
selected item from the list box is the same as one of the items in the table.
If true, then populate the textbox with the corresponding description from
the table.

I am using the code below but just can't get to work. It's not giving the
corresponding description.

P.S. I can write out the vba code and include the descriptions into the If..
then statement. But I'd like to keep the description seperate in a table so
that a user can edit it easily without going into the code.

Any Help!!!!

Below is the code

Daama

Public Sub btnOK_Click()

Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset

Set cn = CurrentProject.Connection
Set rs = New ADODB.Recordset

Dim strField As String
Dim X As Integer
Dim i As Integer

i = lstSelected.ListIndex

If i <> -1 Then

For X = 0 To Me.lstSelected.ListCount - 1
strField = Me.lstSelected.Value
Next X

rs.Open "FieldDescription", cn

If strField = rs.Fields.Item("FieldName") Then

txtFieldsDescription.SetFocus
txtFieldsDescription.Text = rs.Fields.Item("Description")

End If

End If

End Sub
 
B

Bob Miller

What is the source of your listbox? It should be the table
FieldDescription. All that needs to be done is to make sure both
columns are picked up by the listbox (you can hide the description
column.) Then behind the OnClick property of the listbox place this
code:
Me!textboxname = Me!description

There is no need to check that the item is in the table, because if it
is in the list then it is in the table.
 
Top