Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

creating unique field by using multiple fields

Status
Not open for further replies.

wshs

Programmer
Nov 22, 2005
220
US
it seems like i can never get a clear answer for this question...
i would like to create a "unique" field which contains multiple field information.
for example.
lets say txt1 = abc
txt2 = 123
txt3 = uni

i want this unique field(lets say txt0) to grab those automatically and display (txt0=) abc123uni.

how can i approach this?
 
In very simple terms you could concatenate the values in the 3 fields (e.g. me.txt0.value = me.txt1.value & me.txt2.value & me.txt3.value.

Having said that, are you going to run this from a command button or in the afterUpdate event of one or more of the fields, or when record is saved, etc.

Also, I presume you want some check to be performed that all 3 fields contain a legitimate value before populating txt.0. That is you don't want txt0 to reflect only values in txt1 and txt3. Also, you want error checking to avoid other issues (like Invalid Use of Null, Error 94) etc.

Also, you might want to enforce legitimate entries to txt1-txt3. For example, 'A123' might be valid but '#*Y' might not. These could be handled thru inputmasks or by checking value of field in code etc.

Hope this give you some ideas.
 
I would approach this through a form.

On the After Update event of txt3, put the following code:

Me.txt0 = Me.txt1 & Me.txt2 & Me.txt3

I've never tried this before the record is saved, so I don't know if it will work. You may need to play with that aspect a little to figure out the best event to do this one. You could try adding .Value after each of the three fields, to see if that will pull it up before the record is saved.

The problem is this. If this is your unique field, there is no checking being done while the other fields are being filled in.

It might be better to have your table set up with txt1, 2, and 3 as primary keys together. Then have txt0 be simply a display on the form. --Just a thought.
 
i'll give that a try. thx for the quick response guys
 
one problem... i can't update the record that are already there...
 
You could update txt0 field by using an update query that concatenates the values of the other three fields and append that to txt0 - but my same concerns about missing values, etc in my earlier post still apply.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top