DLookup refresh help needed.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

In my form I have a list box for location. Using the value selected in the
list box I fill two other fields (building and room) with information from a
different table than the form is based on. This works great. It also works
fine when I display already existing records. However, if I change the
existing value in the list box the fields using DLookup do not get updated to
the correct corresponding values. Any suggestions on how to make that work?
 
Linda said:
In my form I have a list box for location. Using the value selected
in the list box I fill two other fields (building and room) with
information from a different table than the form is based on. This
works great. It also works fine when I display already existing
records. However, if I change the existing value in the list box the
fields using DLookup do not get updated to the correct corresponding
values. Any suggestions on how to make that work?

In the AfterUpdate event of the ListBox...

Me.FirstLookupControlName.Requery
Me.SecondLookupControlName.Requery
 
Two alternatives.

1. In the click event of the list box, add some code that will update the
text fields you have. Something like:

Private Sub lst_YourListName_Click

me.txt_SomeField = me.lst_YourListName * 3
me.txt_SomeOtherField = DLOOKUP("SomeField", "SomeTable", "[FieldName] =
" & me.lst_YourListName

end sub

2. Another way to do this is to modify the query that is used as the
RowSource for the listbox. Join the the query that is the rowsource for this
control to the table that contains the additional information you want and
add those field to the query. If you go this route, add the additional
fields on to the end of the query. You will want to increase the columns in
the column count portion of the properties window, and will probably want to
make their column widths equal to zero. Then, in the click event, do
something like:

Private Sub lst_YourListName_Click

me.txt_SomeField = me.lst_YourListName.column(3)
me.txt_SomeOtherField = me.lst_YourListName.Column(4)

end sub

HTH
Dale
 
Back
Top