Autocomplete

L

LMB

I think it would be called autocomplete. I have 2 tables. How can I make a combo box on a form to automatically insert the specialty of the physician when I select the physician's name? I don't understand SQL so I need to use wizards and the toolbox.

TblPhysician
PhysicianID (pk)
PhysicianLName
PhysicianFName
PhysicianNumber
PhysicianSpecialtyID (fk)

TblPhysicianSpecialty
PhysicianSpecialtyID (pk)
PhysicianSpecialty

Thanks,
Linda
 
K

Ken Snell [MVP]

Perhaps you can use the combo box and its columns to do what you wish. See
The ACCESS Web for some ways to do this:
http://www.mvps.org/access/forms/frm0058.htm

--

Ken Snell
<MS ACCESS MVP>



I think it would be called autocomplete. I have 2 tables. How can I make a
combo box on a form to automatically insert the specialty of the physician
when I select the physician's name? I don't understand SQL so I need to use
wizards and the toolbox.

TblPhysician
PhysicianID (pk)
PhysicianLName
PhysicianFName
PhysicianNumber
PhysicianSpecialtyID (fk)

TblPhysicianSpecialty
PhysicianSpecialtyID (pk)
PhysicianSpecialty

Thanks,
Linda
 
L

LMB

OK..I made a table tblPersons by following the directions on the Forms hyperlink (I pasted the instruction at the bottom). I don't know what to do with that little *****Code Start section*****

tblPersons
PersonID
FName
MName
LName

qryPersons
PersonID
LName

I made a form with a text box and a combobox and I set the form properties to qryPersons

cboPersonsID
RowSourceType property is Table/Query
RowSource set to qryPersons

Set the Bound Column property of cboPersonsID to 1
Set the Column Count property to 2
Set the Column Width property to this expression: 1":0"

Set the Control Source of a textboy to this expression
=[cboPersonsID].[Column](1)

The combobox has the ID number but not the LName

The textbox has #Name? in it.


Instructions from website:


(Q) How do I have a textbox automatically fill in with a value after I select an item from a combo box on a form (e.g., select a person's ID in a combo box, and have the person's last name automatically display in a textbox)?

(A) The way to do this depends upon whether the textbox is bound to a field in the form's Record Source or not.

Unbound Textbox
In this example, we'll assume that your desired information is in a table named tblPersons, and that this table contains four fields: ID (the person's ID); FirstName (the person's first name); MiddleName (the person's middle name); and LastName (the person's last name).

Set the Row Source Type property of the combo box (assume it's named cboPersonID) to "Table/Query". Set the Row Source to a query that is based on tblPersons and that selects the ID and LastName fields:



' ***** Code Start *****
SELECT ID, LastName
FROM tblPersons
ORDER BY ID;
' ***** Code End *****Set the Bound Column property of cboPersonID to 1.
Set the Column Count property to 2.
Set the Column Widths property to this expression: 1";0".

Set the Control Source of a textbox (assume it's named txtPersonName) to this expression:

=[cboPersonID].[Column](1)

Note that the Column property of a combo box is "zero-based," meaning that the first column (field) in the combo box's Row Source is column 0, the second column is column 1, etc.

When you make a selection of a person's ID in the combo box, the textbox will automatically display the person's name. You can extend this example to include more textboxes by adding more fields to the combo box's Row Source query and setting the Control Source of each textbox to the appropriate column number of the combo box.
 
K

Ken Snell [MVP]

What you describe as your setup appears correct. The "#Name?" error
indicates that your form does not contain a combo box named cboPersonsID.
Perhaps it should be cboPersonID?

What do you mean you "set the form properties to qryPerson"? Do you mean
that the form's RecordSource is set to qryPersons?
--

Ken Snell
<MS ACCESS MVP>


OK..I made a table tblPersons by following the directions on the Forms
hyperlink (I pasted the instruction at the bottom). I don't know what to do
with that little *****Code Start section*****

tblPersons
PersonID
FName
MName
LName

qryPersons
PersonID
LName

I made a form with a text box and a combobox and I set the form properties
to qryPersons

cboPersonsID
RowSourceType property is Table/Query
RowSource set to qryPersons

Set the Bound Column property of cboPersonsID to 1
Set the Column Count property to 2
Set the Column Width property to this expression: 1":0"

Set the Control Source of a textboy to this expression
=[cboPersonsID].[Column](1)

The combobox has the ID number but not the LName

The textbox has #Name? in it.


Instructions from website:


(Q) How do I have a textbox automatically fill in with a value after I
select an item from a combo box on a form (e.g., select a person's ID in a
combo box, and have the person's last name automatically display in a
textbox)?

(A) The way to do this depends upon whether the textbox is bound to a field
in the form's Record Source or not.

Unbound Textbox
In this example, we'll assume that your desired information is in a table
named tblPersons, and that this table contains four fields: ID (the person's
ID); FirstName (the person's first name); MiddleName (the person's middle
name); and LastName (the person's last name).

Set the Row Source Type property of the combo box (assume it's named
cboPersonID) to "Table/Query". Set the Row Source to a query that is based
on tblPersons and that selects the ID and LastName fields:



' ***** Code Start *****
SELECT ID, LastName
FROM tblPersons
ORDER BY ID;
' ***** Code End *****Set the Bound Column property of cboPersonID to 1.
Set the Column Count property to 2.
Set the Column Widths property to this expression: 1";0".

Set the Control Source of a textbox (assume it's named txtPersonName) to
this expression:

=[cboPersonID].[Column](1)

Note that the Column property of a combo box is "zero-based," meaning that
the first column (field) in the combo box's Row Source is column 0, the
second column is column 1, etc.

When you make a selection of a person's ID in the combo box, the textbox
will automatically display the person's name. You can extend this example to
include more textboxes by adding more fields to the combo box's Row Source
query and setting the Control Source of each textbox to the appropriate
column number of the combo box.
 
L

LMB

Ken,

Ohhh. I didn't name the ComboBox. I named the label for the ComboBox. Whoops...Now it works! Thanks and yes, that was the form's RecordSource.

Linda
What you describe as your setup appears correct. The "#Name?" error
indicates that your form does not contain a combo box named cboPersonsID.
Perhaps it should be cboPersonID?

What do you mean you "set the form properties to qryPerson"? Do you mean
that the form's RecordSource is set to qryPersons?
--

Ken Snell
<MS ACCESS MVP>


OK..I made a table tblPersons by following the directions on the Forms
hyperlink (I pasted the instruction at the bottom). I don't know what to do
with that little *****Code Start section*****

tblPersons
PersonID
FName
MName
LName

qryPersons
PersonID
LName

I made a form with a text box and a combobox and I set the form properties
to qryPersons

cboPersonsID
RowSourceType property is Table/Query
RowSource set to qryPersons

Set the Bound Column property of cboPersonsID to 1
Set the Column Count property to 2
Set the Column Width property to this expression: 1":0"

Set the Control Source of a textboy to this expression
=[cboPersonsID].[Column](1)

The combobox has the ID number but not the LName

The textbox has #Name? in it.


Instructions from website:


(Q) How do I have a textbox automatically fill in with a value after I
select an item from a combo box on a form (e.g., select a person's ID in a
combo box, and have the person's last name automatically display in a
textbox)?

(A) The way to do this depends upon whether the textbox is bound to a field
in the form's Record Source or not.

Unbound Textbox
In this example, we'll assume that your desired information is in a table
named tblPersons, and that this table contains four fields: ID (the person's
ID); FirstName (the person's first name); MiddleName (the person's middle
name); and LastName (the person's last name).

Set the Row Source Type property of the combo box (assume it's named
cboPersonID) to "Table/Query". Set the Row Source to a query that is based
on tblPersons and that selects the ID and LastName fields:



' ***** Code Start *****
SELECT ID, LastName
FROM tblPersons
ORDER BY ID;
' ***** Code End *****Set the Bound Column property of cboPersonID to 1.
Set the Column Count property to 2.
Set the Column Widths property to this expression: 1";0".

Set the Control Source of a textbox (assume it's named txtPersonName) to
this expression:

=[cboPersonID].[Column](1)

Note that the Column property of a combo box is "zero-based," meaning that
the first column (field) in the combo box's Row Source is column 0, the
second column is column 1, etc.

When you make a selection of a person's ID in the combo box, the textbox
will automatically display the person's name. You can extend this example to
include more textboxes by adding more fields to the combo box's Row Source
query and setting the Control Source of each textbox to the appropriate
column number of the combo box.
 
L

LMB

I spoke too soon. It worked but when I close out and open the form back up, all the records are blank. I see 1 of 3 records but when I click through the 3 records I entered, both the text box and combo box are blank.


Ken,

Ohhh. I didn't name the ComboBox. I named the label for the ComboBox. Whoops...Now it works! Thanks and yes, that was the form's RecordSource.

Linda
What you describe as your setup appears correct. The "#Name?" error
indicates that your form does not contain a combo box named cboPersonsID.
Perhaps it should be cboPersonID?

What do you mean you "set the form properties to qryPerson"? Do you mean
that the form's RecordSource is set to qryPersons?
--

Ken Snell
<MS ACCESS MVP>


OK..I made a table tblPersons by following the directions on the Forms
hyperlink (I pasted the instruction at the bottom). I don't know what to do
with that little *****Code Start section*****

tblPersons
PersonID
FName
MName
LName

qryPersons
PersonID
LName

I made a form with a text box and a combobox and I set the form properties
to qryPersons

cboPersonsID
RowSourceType property is Table/Query
RowSource set to qryPersons

Set the Bound Column property of cboPersonsID to 1
Set the Column Count property to 2
Set the Column Width property to this expression: 1":0"

Set the Control Source of a textboy to this expression
=[cboPersonsID].[Column](1)

The combobox has the ID number but not the LName

The textbox has #Name? in it.


Instructions from website:


(Q) How do I have a textbox automatically fill in with a value after I
select an item from a combo box on a form (e.g., select a person's ID in a
combo box, and have the person's last name automatically display in a
textbox)?

(A) The way to do this depends upon whether the textbox is bound to a field
in the form's Record Source or not.

Unbound Textbox
In this example, we'll assume that your desired information is in a table
named tblPersons, and that this table contains four fields: ID (the person's
ID); FirstName (the person's first name); MiddleName (the person's middle
name); and LastName (the person's last name).

Set the Row Source Type property of the combo box (assume it's named
cboPersonID) to "Table/Query". Set the Row Source to a query that is based
on tblPersons and that selects the ID and LastName fields:



' ***** Code Start *****
SELECT ID, LastName
FROM tblPersons
ORDER BY ID;
' ***** Code End *****Set the Bound Column property of cboPersonID to 1.
Set the Column Count property to 2.
Set the Column Widths property to this expression: 1";0".

Set the Control Source of a textbox (assume it's named txtPersonName) to
this expression:

=[cboPersonID].[Column](1)

Note that the Column property of a combo box is "zero-based," meaning that
the first column (field) in the combo box's Row Source is column 0, the
second column is column 1, etc.

When you make a selection of a person's ID in the combo box, the textbox
will automatically display the person's name. You can extend this example to
include more textboxes by adding more fields to the combo box's Row Source
query and setting the Control Source of each textbox to the appropriate
column number of the combo box.
 
K

Ken Snell [MVP]

What is the Control Source for the combo box?

--

Ken Snell
<MS ACCESS MVP>

I spoke too soon. It worked but when I close out and open the form back up,
all the records are blank. I see 1 of 3 records but when I click through
the 3 records I entered, both the text box and combo box are blank.


Ken,

Ohhh. I didn't name the ComboBox. I named the label for the ComboBox.
Whoops...Now it works! Thanks and yes, that was the form's RecordSource.

Linda
What you describe as your setup appears correct. The "#Name?" error
indicates that your form does not contain a combo box named
cboPersonsID.
Perhaps it should be cboPersonID?

What do you mean you "set the form properties to qryPerson"? Do you mean
that the form's RecordSource is set to qryPersons?
--

Ken Snell
<MS ACCESS MVP>


OK..I made a table tblPersons by following the directions on the Forms
hyperlink (I pasted the instruction at the bottom). I don't know what
to do
with that little *****Code Start section*****

tblPersons
PersonID
FName
MName
LName

qryPersons
PersonID
LName

I made a form with a text box and a combobox and I set the form
properties
to qryPersons

cboPersonsID
RowSourceType property is Table/Query
RowSource set to qryPersons

Set the Bound Column property of cboPersonsID to 1
Set the Column Count property to 2
Set the Column Width property to this expression: 1":0"

Set the Control Source of a textboy to this expression
=[cboPersonsID].[Column](1)

The combobox has the ID number but not the LName

The textbox has #Name? in it.


Instructions from website:


(Q) How do I have a textbox automatically fill in with a value after I
select an item from a combo box on a form (e.g., select a person's ID in
a
combo box, and have the person's last name automatically display in a
textbox)?

(A) The way to do this depends upon whether the textbox is bound to a
field
in the form's Record Source or not.

Unbound Textbox
In this example, we'll assume that your desired information is in a
table
named tblPersons, and that this table contains four fields: ID (the
person's
ID); FirstName (the person's first name); MiddleName (the person's
middle
name); and LastName (the person's last name).

Set the Row Source Type property of the combo box (assume it's named
cboPersonID) to "Table/Query". Set the Row Source to a query that is
based
on tblPersons and that selects the ID and LastName fields:



' ***** Code Start *****
SELECT ID, LastName
FROM tblPersons
ORDER BY ID;
' ***** Code End *****Set the Bound Column property of cboPersonID to
1.
Set the Column Count property to 2.
Set the Column Widths property to this expression: 1";0".

Set the Control Source of a textbox (assume it's named txtPersonName) to
this expression:

=[cboPersonID].[Column](1)

Note that the Column property of a combo box is "zero-based," meaning
that
the first column (field) in the combo box's Row Source is column 0, the
second column is column 1, etc.

When you make a selection of a person's ID in the combo box, the textbox
will automatically display the person's name. You can extend this
example to
include more textboxes by adding more fields to the combo box's Row
Source
query and setting the Control Source of each textbox to the appropriate
column number of the combo box.
 
L

LMB

There wasn't any. Now it's ID so it's working again. Thank-you!

Linda

What is the Control Source for the combo box?

--

Ken Snell
<MS ACCESS MVP>

I spoke too soon. It worked but when I close out and open the form back up,
all the records are blank. I see 1 of 3 records but when I click through
the 3 records I entered, both the text box and combo box are blank.


Ken,

Ohhh. I didn't name the ComboBox. I named the label for the ComboBox.
Whoops...Now it works! Thanks and yes, that was the form's RecordSource.

Linda
What you describe as your setup appears correct. The "#Name?" error
indicates that your form does not contain a combo box named
cboPersonsID.
Perhaps it should be cboPersonID?

What do you mean you "set the form properties to qryPerson"? Do you mean
that the form's RecordSource is set to qryPersons?
--

Ken Snell
<MS ACCESS MVP>


OK..I made a table tblPersons by following the directions on the Forms
hyperlink (I pasted the instruction at the bottom). I don't know what
to do
with that little *****Code Start section*****

tblPersons
PersonID
FName
MName
LName

qryPersons
PersonID
LName

I made a form with a text box and a combobox and I set the form
properties
to qryPersons

cboPersonsID
RowSourceType property is Table/Query
RowSource set to qryPersons

Set the Bound Column property of cboPersonsID to 1
Set the Column Count property to 2
Set the Column Width property to this expression: 1":0"

Set the Control Source of a textboy to this expression
=[cboPersonsID].[Column](1)

The combobox has the ID number but not the LName

The textbox has #Name? in it.


Instructions from website:


(Q) How do I have a textbox automatically fill in with a value after I
select an item from a combo box on a form (e.g., select a person's ID in
a
combo box, and have the person's last name automatically display in a
textbox)?

(A) The way to do this depends upon whether the textbox is bound to a
field
in the form's Record Source or not.

Unbound Textbox
In this example, we'll assume that your desired information is in a
table
named tblPersons, and that this table contains four fields: ID (the
person's
ID); FirstName (the person's first name); MiddleName (the person's
middle
name); and LastName (the person's last name).

Set the Row Source Type property of the combo box (assume it's named
cboPersonID) to "Table/Query". Set the Row Source to a query that is
based
on tblPersons and that selects the ID and LastName fields:



' ***** Code Start *****
SELECT ID, LastName
FROM tblPersons
ORDER BY ID;
' ***** Code End *****Set the Bound Column property of cboPersonID to
1.
Set the Column Count property to 2.
Set the Column Widths property to this expression: 1";0".

Set the Control Source of a textbox (assume it's named txtPersonName) to
this expression:

=[cboPersonID].[Column](1)

Note that the Column property of a combo box is "zero-based," meaning
that
the first column (field) in the combo box's Row Source is column 0, the
second column is column 1, etc.

When you make a selection of a person's ID in the combo box, the textbox
will automatically display the person's name. You can extend this
example to
include more textboxes by adding more fields to the combo box's Row
Source
query and setting the Control Source of each textbox to the appropriate
column number of the combo box.
 
G

Guest

..The reason for having the three combo boxes is that I do
not duplicate a record. I need to be sure that the record
selected is the one I want, ie details on a record's
field may be outdated, so I need a mechanism to identify
the changed field. If a field has changed the field and
record needs to be updated or if no match is found a new
record created.
Cascading combo boxes would be an avenue to investigate (
I may need more info on this)
If I choose the any three combo boxes options, would it
mean coding in the AfterUpdate
part of each combo box? Can a control's control source
have multiple entries?
Thanks again. Clive
 
K

Ken Snell [MVP]

I'm sorry for my confusion... are you replying to the original post in this
thread? Or do you have a different question?
 

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