List box issue

T

Thakur8385

I have a text box that searches for data in a table and returns records in a
list box.

How do i populate form fields once I click on any item on the list box...
 
D

Dirk Goldgar

Thakur8385 said:
I have a text box that searches for data in a table and returns records in
a
list box.

How do i populate form fields once I click on any item on the list box...


What do you mean by "populate", in this case? Is your form based on the
table that contains the data you want to see, so all you need to do is
navigate to the selected record? Or is your form based on some other table,
or unbound, and you want to use data from the list box to update fields on
the form? Or what?
 
T

Thakur8385

the search box searches for logs created by a particular user. When i key the
user_id the list box returns the date, time and log_type.
when I click any item i want to use data from the list box to be updated in
the relevant fields so that I can modify the data..
 
D

Dirk Goldgar

Thakur8385 said:
the search box searches for logs created by a particular user. When i key
the
user_id the list box returns the date, time and log_type.
when I click any item i want to use data from the list box to be updated
in
the relevant fields so that I can modify the data..

Is this on a form that has the log table as its recordsource?
 
D

Dirk Goldgar

Thakur8385 said:


You're not giving a lot of detail, you realize?

I conclude that what is needed is to navigate the form to the log record
that matches the user's selection. This is simple enough, but it will be
easier if the log table has a single primary key field, and whether the list
box includes this primary key, possibly as a hidden column.

First, let's assume the table has a numeric primary key field called LogID,
and that this key field is included as the bound column of the list box.
This example of code for the list box's AfterUpdate event will navigate your
form to the record with that LogID. I'm also assuming, for the example,
that the list box is named "lstLogEntries".

'----- start of code -----
Private Sub lstLogEntries_AfterUpdate()

With Me.lstLogEntries

If Not IsNull(.Value) Then
Me.Recordset.FindFirst "LogID=" & .Value
End If

End With

End Sub
'----- end of code -----

If the table has no single primary key field, then the FindFirst expression
must be more complex and will involve various columns of the combo box, and
I would need to know what data is in what column, as well as what the field
names are, to adapt the code.
 
T

Thakur8385

You were right...

Many Thanks!!

Dirk Goldgar said:
You're not giving a lot of detail, you realize?

I conclude that what is needed is to navigate the form to the log record
that matches the user's selection. This is simple enough, but it will be
easier if the log table has a single primary key field, and whether the list
box includes this primary key, possibly as a hidden column.

First, let's assume the table has a numeric primary key field called LogID,
and that this key field is included as the bound column of the list box.
This example of code for the list box's AfterUpdate event will navigate your
form to the record with that LogID. I'm also assuming, for the example,
that the list box is named "lstLogEntries".

'----- start of code -----
Private Sub lstLogEntries_AfterUpdate()

With Me.lstLogEntries

If Not IsNull(.Value) Then
Me.Recordset.FindFirst "LogID=" & .Value
End If

End With

End Sub
'----- end of code -----

If the table has no single primary key field, then the FindFirst expression
must be more complex and will involve various columns of the combo box, and
I would need to know what data is in what column, as well as what the field
names are, to adapt the code.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 

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

Top