Results 1 to 9 of 9
  1. #1
    dneruck is offline Novice
    Windows Vista Access 2003
    Join Date
    Apr 2010
    Posts
    6

    Autonumber Problem in adp project

    Hi

    I've been looking at this problem for a couple of weeks. I'm not too familiar with Access, my experience is in vb.net and c#. I'm trying to help a client out since their programmer left (was asked to leave) unexpectedly and there is no documentation for this system which he wrote.

    Ok, the problem that I am having is that there is some code that is trying to reference the autonumber field after immediately after a new record has been created. From what I've read, in an adp project, the autonumber value is not available until AFTER the record has been saved, so the error that I'm getting is actually correct - The value of an (Autonumber) field cannot be retrieved prior to being saved. However this code was working before. The database crashed and this problem started occurring after I was able to recover it. I thought it might have been a case where some of the references weren't the same as the project was created in Access 2003, and we had a references to Access 2007 (12.0 object library). I set up a test environment with only Access 2003 installed and used the 11.0 object references but I still received the same error.

    Can anyone help me with this? I've been trying to solve this for a while now.

    Thanks

  2. #2
    SoftwareMatters is offline Access VBA Developers
    Windows XP Access 2003
    Join Date
    Mar 2009
    Location
    Dorset
    Posts
    274
    Could you post the code that is trying to run and highlight the line where it fails? Thanks.

  3. #3
    dneruck is offline Novice
    Windows Vista Access 2003
    Join Date
    Apr 2010
    Posts
    6
    This is one place. Sys_update_logID seems to be just some kind of logging procedure so I had commented it out.

    Code:
    Private Sub str_NRNumber_AfterUpdate()
    
    r = SYS_update_logID(Nz(Me.lng_RecordID), "frm__AXIS_Customers.str_NRNumber", str_NRNumber, str_SYS_CurrentUserLogin)
    
    r = FRM_Pop_Customer_Details(Me.Name)
    
    
    'Me.str_Gender = str_GetGender(str_NRNumber)
    
    
    End Sub

    But it is also happening here in the save button:

    Code:
    Private Sub cmd_SaveRecord_Click()
    On Error GoTo Err_cmd_SaveRecord_Click
    
    Dim str_FieldName  As String
    
    
    If Me.NewRecord Then
    If IsNull(Me.lng_AccountNo) Then
    
    Me.lng_AccountNo = Me.lng_RecordID
    
    
    End If
    
    
    If IsNull(Me.lng_CustomerNo) Then
    
    Me.lng_CustomerNo = Me.lng_RecordID
    
    
    End If
    
    
    Else
    
    End If
    
    ....
    
    End Sub

  4. #4
    dneruck is offline Novice
    Windows Vista Access 2003
    Join Date
    Apr 2010
    Posts
    6
    Its happening where there are calls to
    Me.lng_RecordID

  5. #5
    SoftwareMatters is offline Access VBA Developers
    Windows XP Access 2003
    Join Date
    Mar 2009
    Location
    Dorset
    Posts
    274
    You could try saving the record before the code runs. So, put the following code after the line Dim str_FieldName As String

    docmd.runcommand accmdsaverecord

    The trouble with that though is the rest of the code won't work properly because it tersts for a new record which of course it won't be once saved. To get round that you'd have to take it out of the if statement like this:
    Dim str_FieldName As String

    docmd.runcommand accmdsaverecord

    If IsNull(Me.lng_AccountNo) Then

    Me.lng_AccountNo = Me.lng_RecordID

    End If


    If IsNull(Me.lng_CustomerNo) Then

    Me.lng_CustomerNo = Me.lng_RecordID

    End If

    ...
    End Sub

  6. #6
    maximus's Avatar
    maximus is offline Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    just Check whether all the above controls are on the form. Meaning all the Controls e.g. Me.lng_AccountNo.

    Me.lng_RecordID
    Me.lng_RecordID

    What are the function of these controls. Are they calculative Fields. if yes where do they get there values.

  7. #7
    dneruck is offline Novice
    Windows Vista Access 2003
    Join Date
    Apr 2010
    Posts
    6
    Thanks softwarematters.. that worked. Maximus I me.lng_recordId is the autonumber field on the form which has a record source of lng_recordId from the database

  8. #8
    dneruck is offline Novice
    Windows Vista Access 2003
    Join Date
    Apr 2010
    Posts
    6
    Hi again

    Using the docmd.runcommand accmdsaverecord command that you gave me seems to have caused another problem.

    I saved a record using this command, and then I restored the database on the sql server side from an old backup (I only have one customer number to test with so I wanted to reuse it) . The record that I saved is not in the restored database, but when I open the adp project it is there. I deleted the project and used the project from the zip file that the client had sent and redid all the code changes that I had made but the record that I added is still there. Can anyone help me with what's causing this?

  9. #9
    dneruck is offline Novice
    Windows Vista Access 2003
    Join Date
    Apr 2010
    Posts
    6
    Ok you can ignore that, I was connecting to the wrong server :S

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

Similar Threads

  1. duplicate autonumber
    By rayc in forum Access
    Replies: 5
    Last Post: 06-19-2013, 07:50 AM
  2. Complex VBA Autonumber question
    By Lockrin in forum Access
    Replies: 2
    Last Post: 04-13-2010, 01:25 PM
  3. Resetting autonumber when importing
    By bullwinkle55423 in forum Access
    Replies: 3
    Last Post: 06-30-2009, 11:56 AM
  4. AUTONUMBER
    By J A F F A in forum Database Design
    Replies: 1
    Last Post: 10-03-2007, 10:30 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