Results 1 to 11 of 11
  1. #1
    Douglasrac is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Nov 2010
    Posts
    92

    Question Generated number do not trigger autonumber

    Hi,



    I have a form with 4 fields.

    a) Autonumber
    b) ID copied from a previous form
    c) Date
    d) Integer number

    I put the first record and then I press a button that will generated the other records, based on the first. So autonumber is autonumber, ID is copied again for the other records, Date is +1 month and integer is +1.

    The problem is that when I press the button, the second record is created but do not trigger the autonumber, so it's like no new record was created. I have to go and do something in the field, retype the number, click and press TAB, etc, so the autonumber is generated and I can save and keep pressing the button to generate the next record.

    It's a problem because there is no objective to have a button that generates other records if I have to retype the data again, or do something to trigger the autonumber.

    Can't the button trigger the autonumber, so it's like a new record?

    Here is the code of the button:

    Private Sub NovaDatadePagamento_Click()
    On Error GoTo Err_NovaDatadePagamento_Click

    Const cQuote = """"

    'Date +1 month
    Me!DatadePagamento.DefaultValue = cQuote & DateAdd("m", 1, Me!DatadePagamento.Value) & cQuote

    'Integer +1
    Me!NumerodaParcela.DefaultValue = "'" & Me!NumerodaParcela.Value + 1 & "'"

    DoCmd.GoToRecord , , acNewRec

    Exit_NovaDatadePagamento_Click:
    Exit Sub

    Err_NovaDatadePagamento_Click:
    MsgBox Err.Description
    Resume Exit_NovaDatadePagamento_Click

    End Sub

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Default Values do *not* dirty a record, which is also why you do not get a new ID value. If you go to the new record and then place the value directly in a control,you will then dirty the record.

  3. #3
    Douglasrac is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Nov 2010
    Posts
    92
    Quote Originally Posted by RuralGuy View Post
    Default Values do *not* dirty a record, which is also why you do not get a new ID value. If you go to the new record and then place the value directly in a control,you will then dirty the record.
    There is no way around? There is no way to make the button dirt the record?

  4. #4
    thhui is offline Competent Performer
    Windows XP Access 2002
    Join Date
    Feb 2009
    Posts
    235
    Default value only works for fixed value.
    If it is a dynamic one, better use a command button to trigger a vba code to set its default value instead.

  5. #5
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Quote Originally Posted by Douglasrac View Post
    There is no way around? There is no way to make the button dirt the record?
    In my answer I told you how to achieve the results you wanted.

  6. #6
    Douglasrac is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Nov 2010
    Posts
    92
    Quote Originally Posted by RuralGuy View Post
    In my answer I told you how to achieve the results you wanted.
    Yes but that is the way I do now. And it's not fast enough for me.

    I type the fisrt record, click to save, click on the button to copy the record, modify the record, save. New record, etc.
    Two clicks and 1 type. Before I just needed to press TAB.

    Must be a way, we just don't know. Of course MS predict that people would add several, even thousands of records from a Multiple Itens forms, and they would want to use only the keyboard for it.

    Also pressing TAB do not create a new record. I'm obliged to save first. Very annoying.

  7. #7
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Change the cycle property (on the *other* tab) to all records and put your code in the BeforeUpdate event of the form.

  8. #8
    Douglasrac is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Nov 2010
    Posts
    92

    Question

    Quote Originally Posted by RuralGuy View Post
    Change the cycle property (on the *other* tab) to all records and put your code in the BeforeUpdate event of the form.
    Perfect! Thank you. Now I can create new records with the calculations just pressing tab.

    Just one more problem. Now when pressing TAB, when create a new record I get:

    Run-time error '2105'
    You can't go to the specified record.

    How do I solve this?


    P.S.:

    I commented the message error box. But is that correct? I won't have problem with the data?

    Private Sub Form_BeforeUpdate(Cancel As Integer)

    On Error GoTo Err_NovaDatadePagamento_Click

    Const cQuote = """"
    Me!DatadePagamento.DefaultValue = cQuote & DateAdd("m", 1, Me!DatadePagamento.Value) & cQuote
    Me!NumerodaParcela.DefaultValue = "'" & Me!NumerodaParcela.Value + 1 & "'"

    DoCmd.GoToRecord , , acNewRec

    Exit_NovaDatadePagamento_Click:
    Exit Sub

    Err_NovaDatadePagamento_Click:
    ' MsgBox Err.Description
    Resume Exit_NovaDatadePagamento_Click

    End Sub

  9. #9
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Remove: DoCmd.GoToRecord , , acNewRec from your code. It is no longer needed.

  10. #10
    Douglasrac is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Nov 2010
    Posts
    92
    Quote Originally Posted by RuralGuy View Post
    Remove: DoCmd.GoToRecord , , acNewRec from your code. It is no longer needed.
    Thank you! Now is working as easy as the old way.

  11. #11
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Glad we could help. It takes a while to really understand all of the events and what Access is doing for you behind the scenes.

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

Similar Threads

  1. Replies: 3
    Last Post: 02-02-2011, 08:04 PM
  2. date trigger
    By hyperionfall in forum Access
    Replies: 1
    Last Post: 08-08-2010, 01:15 PM
  3. Trigger subform event
    By tuna in forum Forms
    Replies: 0
    Last Post: 05-09-2010, 06:29 AM
  4. How to validate dynamically generated text box
    By TheFuzzball in forum Forms
    Replies: 1
    Last Post: 10-24-2009, 10:49 AM
  5. From which query is the report generated
    By rukmal82 in forum Reports
    Replies: 6
    Last Post: 09-30-2009, 09:28 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