form value based on query

C

CDD

hello
I have a DB to document a weight loss program. i want to
show the last height of the patient from the last visit to
save having to retype it when creating a new visit on my
subform. The parent form contains the demographics of the
patient. I have set up a textbox in a subform to display
the value.

I created a query that shows the last [height] of the
patient based on the patient number set on the parent form
when run on its own, but when i run the form that is
linked to the value
i get the error #name? . Is there a problem displaying a
query result in a form as a single result? the rest of
the form is not based on the query.
 
W

Wayne Morgan

Are you trying to use a query as the Control Source for a textbox? If so,
try the DLookup function instead.
 
G

Guest

what i truly want to do is to set default values for
visits on multiple less frequently updated table points
such as height, phone #, medications to take the prior
entry for that patient and set it as the default value. I
had been trying to use a query for the control source as a
proof of concept, but just haven't been able to get it to
work. Will i have to use dlookup functions on each textbox?
-----Original Message-----
Are you trying to use a query as the Control Source for a textbox? If so,
try the DLookup function instead.

--
Wayne Morgan
Microsoft Access MVP


hello
I have a DB to document a weight loss program. i want to
show the last height of the patient from the last visit to
save having to retype it when creating a new visit on my
subform. The parent form contains the demographics of the
patient. I have set up a textbox in a subform to display
the value.

I created a query that shows the last [height] of the
patient based on the patient number set on the parent form
when run on its own, but when i run the form that is
linked to the value
i get the error #name? . Is there a problem displaying a
query result in a form as a single result? the rest of
the form is not based on the query.


.
 
W

Wayne Morgan

To set the Default Value to the previously entered value, you set the
Default Value in the BeforeUpdate or AfterUpdate event of the control.
However, this won't have the default value set when you first open the form,
it will simply have it there for the subsequent new records.

Yes, you could use DLookup in each DefaultValue, but if you're going to do
this for multiple controls I would do it differently. Open a recordset in
the form's Load event set to the form's RecordsetClone. Move to the last
entry made, hopefully you have a date/time field or a counter field that
will make this easy. Next, assign the DefaultValue property of the controls
using the values of the fields in the recordset. Don't forget to set the
recordset to Nothing before leaving the Load event. Once you do this, you
could then use the first option above to update the DefaultValue of any
field that you might change the value of.

Example:
Me.txtMyTextbox.DefaultValue = rst![MyField]
 

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

Similar Threads


Top