Hi Paul,
I'm assuming that your dlookup is in the controlsource of the textbox.
Repaint should work for you but you would still need to use the AfterUpdate
event of the combo control since the the combo control's value won't change
until that event has occured (note that controls have Before/After Update
events that occur before the Before/After Update events of the form itself.
To use Repaint, you really should refer to it as a method of the form
instead of using the Docmd.RepaintObject which is actually only provided for
backwards compatibility. For example:
'from the form's class module:
me.Repaint
To answer your second question, yes this code goes into the class module of
the form.
One other thing to consider is that Dlookups are expensive in terms of
processing. One here or there is ok but several on one form can cause a
significant performance penalty. If the values that you are getting via
Dlookup are already being shown in the rowsource of your combobox you can
get rid of the dlookup entirely and just use a reference to that column of
the combo. For example - lets say your combo box is used to select a
student's homeroom teacher from a list of teachers. The combo box would
probably be bound to the TeacherId field but it could also show Teacher's
name and Room Number.
TeacherID TeacherName TeacherRoomNo
23 Adams 201
24 Brown 202
If you want RoomNo to show on the form you can put the following into the
textbox's controlsource:
=Teacherid.column(2)
Without doing an additional Dlookup, the form will always show the value in
the 3rd column (zero based indexing) of the control named 'TeacherId'.
--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.
paul said:
I don't mean to be naive but it comes naturally so a few
questions to your answers:
First, I have a form that has a lot of unbound controls
doing dlookups from a set of related tables (but the form
is bound to students because that is what needs to be
cycled through non randomly). So I have a number of
combo and list boxes that will need to generate a repaint
of the form ASSUMING that would requery the dlookups but
not the query that the form is bound to. If not, I guess
I should shift to requery.
Second, is the only repository for the example code you
wrote in a VBA subroutine?
Thanks,
paul
-----Original Message-----
Where is the Dlookup? If it is in the ControlSource of the textbox
you shouldn't need to do anything but you could requery the textbox:
me.MyText.requery
If the Dlookup is done in another event you need to repeat the
Dlookup in the AfterUpdate event of the combo.
--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.
Paul said:
I need a text box to update (from a DLookup) when a combo
box changes. I haven't written VBA code before but this
seems pretty simple. I have an On Change event for the
the combo box. The code in VBA is one line:
DoCmd.RepaintObject acForm, "Students"
Yet nothing seems to happen when I change the combo. I'm
sure the dlookup is right because I get the right results
if I put the form in design mode and then back to run
mode, i.e., the text box is updated appropriately.
pearls of wisdom?
Thanks,
paul
.