Results 1 to 4 of 4
  1. #1
    eliotchs is offline Novice
    Windows XP Access 2003
    Join Date
    Mar 2011
    Posts
    24

    Adding 1 to a field for a new record

    Hi

    I have a form which queries records by clino
    it is sorting descending by seqno

    something like



    clino seqno data..
    001 5 dataswedxex
    001 4 dataswedxex
    001 3 dataswedxex


    I have a new record button and I would like the textbox for the seqno to populate(and actually not be able to change) with the next number in sequence.. in the example it would be 6


    Thanks
    Joe

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    in a form, on Form_BeforeInsert event, add 1 to the max count...

    [seqno] = dMax("[seqno]","tabl","[clino]='" & txtBoxClino & "'") + 1

  3. #3
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    You can use the DMax domain function to determine the current maximum SeqNo for that client, then add 1:

    me![NewSeqNo] = nz(dmax("seqno", "Tablename","clino = " & me![ClientNo] ), 0) + 1

    Change the italics to the actual names of your tables and form controls.

    If there are no records yet for that Client, the DMax will return Null, so the Nz function is used to give you 0 instead of null.

    You would put this in the code for the button.

    To prevent the textbox from being changed, set its Locked property to Yes. (That does not prevent VBA code from setting it).

    HTH

    John

  4. #4
    eliotchs is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2011
    Posts
    24
    Thanks

    That worked great
    !!!

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

Similar Threads

  1. Multiple entries to one record without adding new field?
    By Yamilet in forum Database Design
    Replies: 7
    Last Post: 06-01-2013, 04:22 PM
  2. Replies: 4
    Last Post: 08-14-2012, 07:14 AM
  3. Replies: 14
    Last Post: 05-25-2012, 02:40 AM
  4. Replies: 9
    Last Post: 06-20-2011, 03:42 PM
  5. Replies: 0
    Last Post: 10-14-2009, 02:44 AM

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