Populating a text box based on combo box data

B

Brian Beck

I have a form (fIncidentReport) in which the user first selects their
district from a combobox (DistrictComboBox). This then auto-populates the
Campus field with a listing of all the campuses that are in that district.
I've figured this coding and it's working very well, but now my problem is
getting this scenario to work with a text box instead of a combo box.

I have a field on the form that is a text box and it will have the name of
the superintendent (SuperintendentFullName) for the district that was
selected in the DistrictComboBox. Now, if I were to make this a combo box
instead, I could easily have it auto-populate with the superintendent's name
by creating a query (qSuperintendent) with the following code:

SELECT tOrgDistrict.CountyDistrictNum, tOrgDistrict.SuperintendentFullName
FROM tOrgDistrict
WHERE
(((tOrgDistrict.CountyDistrictNum)=[Forms]![fIncidentReport]![DistrictComboBox]));

and then using the following code in the SuperintendentFullNameComboBox on
the form:

SELECT qSuperintendent.SuperintendentFullName
FROM qSuperintendent;

Now this works just fine, except for 2 things.

1. The superintendent's name doesn't automatically show up in that field on
the form. The user has to manually enter that field (either by tabbing to
it or with the mouse) and then select the superintendent's name from the
drop down box. True, there is only going to be one name there, but the user
still has to go select it.

2. This really shouldn't be a combo box because this field will only ever
have one value...there is never going to be a combination of
superintendent's for the user to select from.

What I'm wanting then is to be able to populate the text box (let's call it
SuperintendentTextBox) with SuperintendentFullName and allow the user to
either see it, know that it is correct and move on, or to see it, realize
it's wrong and then type in the correct information in that same text box.
Then, when the record is submitted to the database table (tIncident), the
correct SuperintendentFullName will be put there, not the one that was
pulled from tOrgDistrict.

Sorry for being so lengthy, I just wanted to make sure I gave as much
information as possible. I'm doing this in Access 2003 on Windows XP Pro.
Any help would be greatly appreciated.

Thanks.

-Brian
 
B

Brian Bastl

Hi Brian,

Try using the Column index of your DistrictCombobox to populate your
SuperintendentTextBox. Just remember that the column index is "zero based"
meaning that the first column has an index of 0, 2nd column =1, etc...

Private Sub DistrictCombobox_AfterUpdate()

Me.SuperintendentTextBox = Me.DistrictCombobox.Column(1)

End Sub

HTH,
Brian
 
C

cornboy

Hi Brian,

There seems to be some ambiguous information here:

"This really shouldn't be a combo box because this field will only ever

have one value. . ."

But then:

" . . .or to see it, realize it's wrong and then type in the correct
information in that same text box."

If ther can only ever be one value, how can it be wrong? If there are
multiple superintendents, then a combo box would seem appropriate. If
not, then why not just hard code the singular name into the text box?
What am I misundersanding?

Btw, I'm a noobie here and to Access development, so if I'm displaying
my ignorance my apologies.
 
B

Brian Beck

That worked perfectly. The only thing I had to do was go back to the query
I used with DistrictComboBox and add the SuperintendentFullName field.
Thanks for the help!!


Brian Bastl said:
Hi Brian,

Try using the Column index of your DistrictCombobox to populate your
SuperintendentTextBox. Just remember that the column index is "zero based"
meaning that the first column has an index of 0, 2nd column =1, etc...

Private Sub DistrictCombobox_AfterUpdate()

Me.SuperintendentTextBox = Me.DistrictCombobox.Column(1)

End Sub

HTH,
Brian


Brian Beck said:
I have a form (fIncidentReport) in which the user first selects their
district from a combobox (DistrictComboBox). This then auto-populates
the
Campus field with a listing of all the campuses that are in that
district.
I've figured this coding and it's working very well, but now my problem
is
getting this scenario to work with a text box instead of a combo box.

I have a field on the form that is a text box and it will have the name
of
the superintendent (SuperintendentFullName) for the district that was
selected in the DistrictComboBox. Now, if I were to make this a combo
box
instead, I could easily have it auto-populate with the superintendent's name
by creating a query (qSuperintendent) with the following code:

SELECT tOrgDistrict.CountyDistrictNum,
tOrgDistrict.SuperintendentFullName
FROM tOrgDistrict
WHERE
(((tOrgDistrict.CountyDistrictNum)=[Forms]![fIncidentReport]![DistrictComboB
ox]));

and then using the following code in the SuperintendentFullNameComboBox
on
the form:

SELECT qSuperintendent.SuperintendentFullName
FROM qSuperintendent;

Now this works just fine, except for 2 things.

1. The superintendent's name doesn't automatically show up in that field on
the form. The user has to manually enter that field (either by tabbing
to
it or with the mouse) and then select the superintendent's name from the
drop down box. True, there is only going to be one name there, but the user
still has to go select it.

2. This really shouldn't be a combo box because this field will only ever
have one value...there is never going to be a combination of
superintendent's for the user to select from.

What I'm wanting then is to be able to populate the text box (let's call it
SuperintendentTextBox) with SuperintendentFullName and allow the user to
either see it, know that it is correct and move on, or to see it, realize
it's wrong and then type in the correct information in that same text
box.
Then, when the record is submitted to the database table (tIncident), the
correct SuperintendentFullName will be put there, not the one that was
pulled from tOrgDistrict.

Sorry for being so lengthy, I just wanted to make sure I gave as much
information as possible. I'm doing this in Access 2003 on Windows XP
Pro.
Any help would be greatly appreciated.

Thanks.

-Brian
 
B

Brian Bastl

happy to help


Brian Beck said:
That worked perfectly. The only thing I had to do was go back to the query
I used with DistrictComboBox and add the SuperintendentFullName field.
Thanks for the help!!


Brian Bastl said:
Hi Brian,

Try using the Column index of your DistrictCombobox to populate your
SuperintendentTextBox. Just remember that the column index is "zero based"
meaning that the first column has an index of 0, 2nd column =1, etc...

Private Sub DistrictCombobox_AfterUpdate()

Me.SuperintendentTextBox = Me.DistrictCombobox.Column(1)

End Sub

HTH,
Brian


Brian Beck said:
I have a form (fIncidentReport) in which the user first selects their
district from a combobox (DistrictComboBox). This then auto-populates
the
Campus field with a listing of all the campuses that are in that
district.
I've figured this coding and it's working very well, but now my problem
is
getting this scenario to work with a text box instead of a combo box.

I have a field on the form that is a text box and it will have the name
of
the superintendent (SuperintendentFullName) for the district that was
selected in the DistrictComboBox. Now, if I were to make this a combo
box
instead, I could easily have it auto-populate with the superintendent's name
by creating a query (qSuperintendent) with the following code:

SELECT tOrgDistrict.CountyDistrictNum,
tOrgDistrict.SuperintendentFullName
FROM tOrgDistrict
WHERE
(((tOrgDistrict.CountyDistrictNum)=[Forms]![fIncidentReport]![DistrictComboB
ox]));
and then using the following code in the SuperintendentFullNameComboBox
on
the form:

SELECT qSuperintendent.SuperintendentFullName
FROM qSuperintendent;

Now this works just fine, except for 2 things.

1. The superintendent's name doesn't automatically show up in that
field
on
the form. The user has to manually enter that field (either by tabbing
to
it or with the mouse) and then select the superintendent's name from the
drop down box. True, there is only going to be one name there, but the user
still has to go select it.

2. This really shouldn't be a combo box because this field will only ever
have one value...there is never going to be a combination of
superintendent's for the user to select from.

What I'm wanting then is to be able to populate the text box (let's
call
it
SuperintendentTextBox) with SuperintendentFullName and allow the user to
either see it, know that it is correct and move on, or to see it, realize
it's wrong and then type in the correct information in that same text
box.
Then, when the record is submitted to the database table (tIncident), the
correct SuperintendentFullName will be put there, not the one that was
pulled from tOrgDistrict.

Sorry for being so lengthy, I just wanted to make sure I gave as much
information as possible. I'm doing this in Access 2003 on Windows XP
Pro.
Any help would be greatly appreciated.

Thanks.

-Brian
 
B

Brian Beck

The field will only ever have one value in it, because each district can
only have one superintendent. However, since this table was for capturing
specific incidents, the superintendent that was at the district WHEN the
incident happened, may not be the same superintendent that is stored in the
table tOrgDistrict, which usually would have the most current information.
So if the user sees that the current superintendent is not the person who
was superintendent during the incident in question, then they could type in
the correct superintendent name and this would be placed in the
SuperintendentFullName field that will be in the table tIncident.

I hope that cleared it up some for you.
 

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