Combining two or more fields together

G

Guest

Does anyone know the code for combining the text of two or more fields
together to make one field that is the primary key? Thanks in advance.
 
G

Guest

' If you want space between the fields values
KeyField = Field1 & " " & Field2 & " " & Field3

' With no space
KeyField = Field1 & Field2 & Field3
 
R

Rick B

You may be looking for a compound index. That is where you take two or more
fields and consider them to prevent duplicates.

Look at "compound index" in help. It will get you there.

An example might be...

FirstName LastName


You could have several John's and several "Smith"s but only want one JOHN
SMITH. Using a combined index and setting it to not allow duplicates would
accomplish this.
 
J

John Vinson

Does anyone know the code for combining the text of two or more fields
together to make one field that is the primary key? Thanks in advance.

It's neither necessary nor appropriate to create a redundant
concatenated field for this purpose. Instead, use a "composite key" -
ctrl-click the two (or more, up to ten) fields which jointly
constitute the Primary Key, so that they're all highlighted on the
screen, and click the Key icon.

This will allow any individual field to have duplicates, but will
prevent any records containing all of the fields duplicated.


John W. Vinson[MVP]
 

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