Results 1 to 6 of 6
  1. #1
    Willump is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    5

    Beginner question regarding generating fields

    Hi, Please forgive me as I am new to these forums and access. I am trying to generate an ID field within a form. The format of the ID is 01TomSmi (ID number one higher than the last, followed by the first 3 letters the letter of the first name and the first 3 letters of the last name). I want the ID to automatically generate in my form. I have used the following code. =Left([Firstname],3) & Left([Lastname],3) & Max(Left([IDnumber],2)+1), although I am unsure where to put it. If I put the code in the control source, I get an error saying the primary key is null, although I can see it has generated correctly. If i put it in the default value it does not update when I change the name in the form.



    Any help would be appreciated, thanks.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    It would be handled like a calculated field:

    http://allenbrowne.com/casu-14.html
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Willump is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    5
    The field I am trying to calculate is a primary key, and access wont allow me to change it to a calculated field. There is already values in the field, I just want it to work out a new ID when submitting a form. I'm not sure if this should be done in the form, the table or a query .

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Sorry, I meant the second section, "you want to store a calculated result anyway".
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    Willump is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    5
    I think the formula I used is correct, I just don't know what to do with it. Do I need to create a new calculated field and then change the ID to this field? If I do this then the Primary key is temporarily null and so I can't save any records. Sorry if I'm not making myself clear. I think it would be easier to use a default value, but then the name part of the ID does not work as there is no name when I first open the form, and it does not update.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No, you'd use code from the link like:

    Code:
    Private Sub Quantity_AfterUpdate()   
      Me.Fee = Round(Me.Quantity * Me.UnitPrice * 0.1, 2) 
    End Sub
    But using your formula. In other words, you're placing your value into a bound textbox using code rather than having the formula as the control source.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Beginner - basic question
    By kevinnice in forum Programming
    Replies: 3
    Last Post: 03-08-2012, 11:31 AM
  2. Possible Access Question (total beginner)
    By SRobertson in forum Access
    Replies: 1
    Last Post: 01-12-2012, 06:01 PM
  3. Newbie question on generating reports
    By nadeem in forum Reports
    Replies: 1
    Last Post: 08-17-2011, 09:04 AM
  4. Beginner-Importing excel table question
    By simmonsmtb in forum Import/Export Data
    Replies: 3
    Last Post: 03-07-2011, 11:55 AM
  5. Relational Structure - Beginner Question
    By CrazyFileMaker in forum Access
    Replies: 2
    Last Post: 01-02-2011, 11:28 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