Results 1 to 4 of 4
  1. #1
    bubai is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Nov 2014
    Location
    Dhaka
    Posts
    162

    How to save incremented value from a form-textbox to it's underlying field before saving the record.

    I have a table (Cons) where I record all the transaction and which I fill with data through a form. First column of the table is a ID column and is primary key. I have set it's data type as integer and not as an autonumber in order to save some megabytes in the database size. In the form Cons_ID is the text box from which field value is saved to the table's ID field which is also named Cons_ID. I need to put some kind of event procedure in the form which by default saves an incremented number which is greater by one from the maximum value in the ID field before the form's data is saved to the table.
    I have attached a sample.


    G.zip

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,530
    Why not make life easy for yourself an make Cons_ID an Auto-Number?
    If you must do it the more difficult way, try the following code in the forms Before Update event:
    If Me.NewRecord Then
    Me.Cons_ID = DMax("Cons_ID", "Cons") + 1
    End If
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    bubai is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Nov 2014
    Location
    Dhaka
    Posts
    162
    Quote Originally Posted by Bob Fitz View Post
    Why not make life easy for yourself an make Cons_ID an Auto-Number?
    If you must do it the more difficult way, try the following code in the forms Before Update event:
    End If
    Cheers Mate!
    It's working fine.

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,530
    Quote Originally Posted by bubai View Post
    Cheers Mate!
    It's working fine.
    which method did you use to get it working: Code or Auto-Number
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

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

Similar Threads

  1. Replies: 3
    Last Post: 06-27-2019, 03:18 PM
  2. Replies: 6
    Last Post: 06-19-2018, 03:38 PM
  3. Replies: 7
    Last Post: 09-11-2014, 12:26 PM
  4. Replies: 8
    Last Post: 09-27-2012, 11:12 AM
  5. Replies: 1
    Last Post: 04-25-2012, 11:56 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