Results 1 to 6 of 6
  1. #1
    djcmalvern is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Location
    Worcester, UK
    Posts
    9

    Back in ACCESS 2007 Calculated field in query

    Hi All,



    Problem is to create a generated userID given (via a data entry mechanism) a Forename, Surname and the number from the primary key autonumber fields. In Access 2010 this was no problem to do using Calculated fields in the table definition. I used Left([Forename1], 3], left([Surname], 3) then concatenation with the PK number in a 3rd calculated field. Easy! BUT, I now find that the same thing has to be done in ACCESS 2007, ie no calculated fields in tables. So, I turn to calculated fields in queries? Is that correct? But how do I run an Append query to allow a new student to be added to the database, with the new calculated StudentID. That is, to enter a new row to my Student table with the 'calculated' student ID placed in the field in the table? Or should I be doing something much simpler? All help welcomed!

    djcmalvern

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,893
    Much simpler is to use autonumber as primary key and just calculate the 'StudentID' whenever needed for display or for use as field to sort/search.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    djcmalvern is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Location
    Worcester, UK
    Posts
    9

    An ACCESS 2007 query problem

    Quote Originally Posted by June7 View Post
    Much simpler is to use autonumber as primary key and just calculate the 'StudentID' whenever needed for display or for use as field to sort/search.
    Thanks,

    I understand that, but the project spec is specific that the StudentID is to be 'generated' for storage in the table and is to be of the form LLLLnnnn. So I thought of just adding 1000 to the primary key for the nnnn bit and the Left() functions for the other bit, but is there a way to achieve this in ACCESS 2007 using queries with calculated fields or something. I guess it is an easy thing to do with VBA but, for the purpose of this little project, "programming will not be required". I'm confused!

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,893
    The value can be calculated whenever needed, saving to table requires code. Also, to use the autonumber field in the construct requires the record to be committed to table first. I do have code that generates a unique ID but does not involve autonumber. So, the point is there is no 'simple' way to do what you want and does require programming. I use only VBA and not sure macro can accomplish.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    djcmalvern is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Location
    Worcester, UK
    Posts
    9
    Thanks June7. I'll just do it with VBA and see how things work out. Much obliged.

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,893
    Minor correction to my previous statement. The expression can use the autonumber field before the record is committed. I tested that.

    Review discussion of topic in https://www.accessforums.net/databas...ice-34483.html
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 02-13-2013, 10:15 AM
  2. Calculated filed in Access 2007
    By fekrinejat in forum Access
    Replies: 6
    Last Post: 02-05-2013, 07:54 PM
  3. Replies: 3
    Last Post: 04-18-2012, 07:10 AM
  4. access 2007; sql query in a field?
    By cmdturk in forum Access
    Replies: 4
    Last Post: 12-16-2009, 10:25 AM
  5. Replies: 1
    Last Post: 02-05-2009, 04:53 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums