Results 1 to 19 of 19

Thread: [RESOLVED] Problem : Set the Seed of an AutoNumber using ADOX

Threaded View

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2010
    Posts
    1,103

    Resolved [RESOLVED] Problem : Set the Seed of an AutoNumber using ADOX

    I have a problem when I am setting the Seed of an AutoNumber using ADOX. VB report errors when VB executing the codes if 2 or more VB applications are connecting to the table. But if I remove the line (bellow Bold),then it come to be multi-instances.

    oCat.Tables("tblFile").Columns("ID").Properties("Seed") = NewID + 1

    Code:
    Dim oCnn As Object ' ADODB.Connection
    Dim oRS As Object
    Dim objJRO As Object
    
    Dim oCat As Object 'New ADOX.Catalog
    Dim NewID As Long  'this will contain the seed value.
    
    Dim hFile As Long
    
    ' Insert the object into the database
    
        On Error GoTo vbErrorHandler
    
        If Not InitDB(oCnn, Me.DatabaseName, Me.UserName, Me.Password) Then Exit Function
        Set oRS = CreateObject("ADODB.Recordset") ' New ADODB.Recordset
    
        'reset the seed value of your AutoNumber field (the value of the new identity)
        Set oRS = oCnn.Execute("SELECT MAX(ID) FROM tblFile")
        NewID = oRS.Fields(0).Value  '0 specifies that we want the first field
        oRS.Close
    
        Set oCat = CreateObject("ADOX.Catalog") ' New ADOX.Catalog
        oCat.ActiveConnection = oCnn
        oCat.Tables("tblFile").Columns("ID").Properties("Seed") = NewID + 1
        oCat.Tables("tblFile").Columns.Refresh
        Set oCat = Nothing
    Last edited by Jonney; Apr 22nd, 2010 at 04:31 AM. Reason: Wrong thread,don't know how to move to database thread

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width