Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2004

    Unanswered: Quick auto increment subform question

    I have a main form and a subform. Everytime a record is added to the subform it will increment by 1. Then when the record is changed on the main form it starts back at 0, so on and so forth. Why doesn't the below work, it just stays at zero?

    Private Sub Form_Current()
    Dim atonumber As Long

    Me.txtauto = atonumber
    atonumber = atonumber + 1
    End Sub

  2. #2
    Join Date
    Nov 2003
    Put the code in the BeforeUpdate event of the sub form. This event occurs after you have entered the data for the new record, but before the data is updated in the table


  3. #3
    Join Date
    Sep 2003
    Where is the variable declared?
    What is the variables scope?
    Is the variable initialized?

    If you want it to increment when a record is created, are you sure you want to increment it in the current event?

    maybe you could add, if then increment....

    I can't say why the variable remains zero. I'm thinking scope is the problem but I need more info...

  4. #4
    Join Date
    Sep 2004
    I thought that
    Dim atonumber As Long would declare the variables. I am new to VBA and learning as I go along but I thought that I can declare in the sub.

    Basically, if the subform has records the text field that contains the auto increment will already be number. If the subform has 3 records alreay, the number will start at 3 and if I add a new record then it will increment by +1. When I change the main record another the counter will be a zero if no records are in there.

    Right now, what I have when I step through it stays at zero and doesn't increment. When I select a new record the count is still zero.
    Last edited by Ronbegone; 10-26-04 at 19:08.

Posting Permissions

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