AllExperts > Using MS Access 
Search      
Using MS Access
Volunteer
Answers to thousands of questions
 Home · More Using MS Access Questions · Answer Library  · Encyclopedia ·
More Using MS Access Answers
Question Library

Ask a question about Using MS Access
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Rob Henderson
Expertise
I can answer most MS Access design questions. I also welcome questions on database design and implementation and VBA programming questions. I also have expierence in application design for all the Office components (Excel, Outlook, etc).

 
   

You are here:  Experts > Computing/Technology > Business Software > Using MS Access > field accessing other fields

Using MS Access - field accessing other fields


Expert: Rob Henderson - 2/10/2005

Question
Hi Rob,

I need a field in an access database that will automatically populate with a combination of other field values.  For example, I have two fields, "customer code" and "access type".  If I enter the text 001234 in customer code, and D in access type, I would like the field "ccat" to return the text 001234D automatically.

How do I make the "ccat" field do this?

Also, I want the "ccat" field to be a key field, no duplicates.

Thanks for your help.

Answer
Hi Jerry

You can do this quite easily by using some VBA

Sub CombineFields()


   Dim strTextBox1         As String
   Dim varLookUp           As Variant
   
   
   ' Grab the values to parse
   strTextBox1 = Forms!NameofYourForm!NameofYourField1.Value & Forms!NameofYourForm!NameofYourField1.Value
   
   ' Perform a DLookUp on the table to establish if this is unique
   varLookUp = DLookup("yourfieldtosearchfor", "yourtable", "yourfieldtosearchfor'" = strTextBox1 & "'")
   
   ' Check the return value - if nothing - flag a message
   If IsNull(varLookUp) = False Or varLookUp <> "" Then
   
       MsgBox "This value is a duplicate.", vbInformation, "Duplicate Found."
   
   
   End If


End Sub

The above sub can be called from a command button to check the duplicate status or from the Before_Update event of the textbox itself

simply call using Call CombineFields()

HTH

rob  

Add to this Answer   Ask a Question


 
User Agreement | Privacy Policy | Kids' Privacy Policy | Help
Copyright  © 2008 About, Inc. AllExperts, AllExperts.com, and About.com are registered trademarks of About, Inc. All rights reserved.