Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 4th, 2003, 10:55 AM
Authorized User
 
Join Date: Nov 2003
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default auto update table field

I have a table that stores contact information for a mailing list. I would like to automatically create a new field from two other fields within the same table.

i.e.
first_name and last_name are input on a form. I would like an additional field titled full_name that automatically populates in the following format: "last_name, first_name"

I tried using expressions etc.. and no luck. I'm rather new at this so please excuse if it is a simple issue.

Thanks in advance for any help,
Nick
 
Old November 4th, 2003, 04:09 PM
Authorized User
 
Join Date: Oct 2003
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Nick,

I am assuming that you only want to populate the full_name field automatically, not allowing the users to actual populate it themselves.

A simple solution could be put within your BeforeUpdate() at the form-level (as opposed to the field-level) in your form which would appear as follows:

Private Sub Form_BeforeUpdate(Cancel As Integer)
   If Not IsNull(Me.first_name) and Not IsNull(Me.last_name)
      Me.full_name = Me.last_name & ", " & Me.first_name
   End If
End Sub


This code assumes and will perform the following:
 - full_name is a column defined in your underlying table and
   is also present on the user form (you will probably want to
   lock the field to the user)
 - The "Me" keyword refers to the current form
 - full_name will only be populated if BOTH the first and last
   names are present on the form.

You can also have the full_name field automatically immediately after first or last name is updated by moving this exact code under the AfterUpdate() events of both the first_name and last_name fields on the form. The only difference is that the AfterUpdate() on the fields will show immediate results (provided that values exist in both the first and last name fields) and the BeforeUpdate() on the form itself will only update the full_name field when the user attempts to close the form, go to another existing record, or attempts to add a new record.

Hope this helps.

Warren
:D
 
Old November 4th, 2003, 05:28 PM
Authorized User
 
Join Date: Nov 2003
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks a lot!

I put the code into the On Current event and it works fine. For some reason, it gave me an error on the after update and before update.

Thanks again.





Similar Threads
Thread Thread Starter Forum Replies Last Post
auto update from 1 table to column in another tabl headwaters Access 1 December 1st, 2008 08:39 AM
Creating an auto update date field tmswenson MySQL 3 January 4th, 2006 03:12 PM
Table field update ibelta Access 4 February 12th, 2005 08:22 PM
Auto update timestamp field TwoNames PHP Databases 2 September 26th, 2004 06:01 PM
Update city field based on zip field nganb SQL Server ASP 0 April 22nd, 2004 10:30 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.