1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: Access 2007 - copy calculated reference number to underlying table

Discussion in 'Business Applications' started by JoeBlack999, Dec 11, 2008.

Thread Status:
Not open for further replies.
Advertisement
  1. JoeBlack999

    JoeBlack999 Thread Starter

    Joined:
    May 12, 2008
    Messages:
    77
    I haven't used Access for about a year and rust has set in. I have been asked to generate a reference number to identify clients. The reference number uses the first three letters from each of the clients first and last name and the unique (autonumber).

    I can do this on a form view easily enough:

    =Left([fsub_Staff].[Form]![FirstName],3) & Left([fsub_Staff].[Form]![LastName],3) & [fsub_Staff].[Form]![ID]

    However, I would really need this to be hard coded back into the underlying database table, consisting of the first, last and autonumber field (as reference).

    Any assistance would be appreciated.
     
  2. OBP

    OBP Trusted Advisor

    Joined:
    Mar 8, 2005
    Messages:
    18,834
    I am not sure why they need this reference number, as the Autonumber does the job as far as the database is concerned.
    But as you have the job to do, just add the new Reference Number field to the Data Input Form and then use the equivalent VBA version of your Formula in the First and Last Name Fields After Update Event Procedures.
    The VBA Version is
    me.referencenumber = Left(me.[FirstName],3) & Left(me.[LastName],3) & me.[ID]
    where referencenumber is the actual name of your new field.
    It needs to be in both fields in case someone changes either field later.

    You can also create an update Query to update any current data.
     
  3. JoeBlack999

    JoeBlack999 Thread Starter

    Joined:
    May 12, 2008
    Messages:
    77


    I assume its the code builder, option on the afer update event procedure?

    Private Sub FirstName_AfterUpdate()
    Me.Reference = Left(Me.[FirstName], 3) & Left(Me.[LastName], 3) & Me.[ID]
    End Sub


    Access spits out some errors, what or where have I goofed up?
     
  4. OBP

    OBP Trusted Advisor

    Joined:
    Mar 8, 2005
    Messages:
    18,834
    Sorry , I missed your reply yesterday, what errors do you get?
    You may need to set some Library references to use the VBA code.
     
  5. JoeBlack999

    JoeBlack999 Thread Starter

    Joined:
    May 12, 2008
    Messages:
    77

    Sorry for the delay in responding - the code is working - must have not pasted it in correctly - thanks for your help - problem now solved.l
     
  6. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/778423