Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2004

    Unanswered: Auto Populate a filed when a new record is entered


    I have small table with three fileds. The table filed are FName, LName and ID.

    I want to have the ID field autopopulate with a first characher of the FName and the first Character of the LName.

    How can i accomplish this?

    Is there an easy way to accomplish this?

    All help is appreciated..

  2. #2
    Join Date
    Nov 2004
    out on a limb
    Provided Answers: 59
    you need to put some code behind a suitable event (think of an event as a hook to associate a fragment of code which reacts to an action or event triggered elsewhere)
    probably the best event is going to be the on change or on lost focus events
    you need to use some vba functions to retrieve the first character of each element you want.

    id suggest creating a function to do the actual deed

    private sub CreateID()
    Id = left$(FName,1) & left$(UName,1)
    end sub

    you can then call that function from whatever events you want (id suggest probably the on change and on lost focus events in the code for the controls holding FNAME & UNAME.. in the above example ive assumed that your control names are the same as the column names.

    however that skeleton sub routine isn't going to pass muster.. you may want to trap for null values
    you may need to inhibit changes once a record has been created.. ie you can only set he vlaue of the id column whne the record is created.. but not after that.

    however, before doing that I'd want to check my id is correct and valid.. what meanijn does it have... should Id be unique.. if so then merely taking the first 2 characters will not suffice.. you need to add soem numeric component.

    as the two characters are derviced data.. shoudl they even be stored separately...... they after all can be recreated in a query easily enough...

    select left$(FName,1) & left$(UName,1) as Id from <mytable>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts