Auto-populate text boxes based on a query

S

Scott

Hello,

I am a vb novice, so bear with me. I have a form for HR Partners in
my company to request new positions be built for the organizations
they support. About half of the information on each record can be
assumed based on the Organization for which the request is being
generated (ie. HR Partner, Org Executive, Financial Controller,
etc.). I am trying to write vb that will, upon selection of an
Organization from a combobox, auto-populate these fields in the form
with the information corresponding to that Organization. My
assumption is that I should be able to query for distinct
organizations and their corresponding data elements, then set the
textboxes' controlsources to these fields based on the value selected
in the 'Organization' combobox.

I hope that made sense. Any thoughts? Am I even in the ballpark?
 
D

Dennis

You can either put code in the After_Update Event of the combo box similar to
this
TextBoxName = DLookUp("[FieldName]","Organisations Table","[FieldInTable] =
" & [ComboBoxName])
This line assumes that the value in the combo box and in the Organisations
table is numeric. If it is text then use
TextBoxName = DLookUp("[FieldName]","Organisations Table","[FieldInTable] =
'" & [ComboBoxName] & "'")
Repeat for other TextBoxNames

Alternatively you can set the control source property of the textboxes to
=DLookUp("[FieldName]","Organisations Table","[FieldInTable] = " &
[ComboBoxName])
or
=DLookUp("[FieldName]","Organisations Table","[FieldInTable] = '" &
[ComboBoxName] & "'")
 
S

Scott

You can either put code in the After_Update Event of the combo box similar to
this
TextBoxName = DLookUp("[FieldName]","Organisations Table","[FieldInTable] =
" & [ComboBoxName])
This line assumes that the value in the combo box and in the Organisations
table is numeric. If it is text then use
TextBoxName = DLookUp("[FieldName]","Organisations Table","[FieldInTable] =
'" & [ComboBoxName] & "'")
Repeat for other TextBoxNames

Alternatively you can set the control source property of the textboxes to
=DLookUp("[FieldName]","Organisations Table","[FieldInTable] = " &
[ComboBoxName])
or
=DLookUp("[FieldName]","Organisations Table","[FieldInTable] = '" &
[ComboBoxName] & "'")



Scott said:
I am a vb novice, so bear with me.  I have a form for HR Partners in
my company to request new positions be built for the organizations
they support.  About half of the information on each record can be
assumed based on the Organization for which the request is being
generated (ie. HR Partner, Org Executive, Financial Controller,
etc.).  I am trying to write vb that will, upon selection of an
Organization from a combobox, auto-populate these fields in the form
with the information corresponding to that Organization.  My
assumption is that I should be able to query for distinct
organizations and their corresponding data elements, then set the
textboxes' controlsources to these fields based on the value selected
in the 'Organization' combobox.
I hope that made sense.  Any thoughts?  Am I even in the ballpark?-Hide quoted text -

- Show quoted text -

Thanks a bunch Dennis! It worked perfectly.
 

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