R
RDub
I think I need to be able to mess around the Autonumber Seed values in a
couple of Access databases. Yea I know this is a bad practice, but I just
need to get this done so I can live to fight the real battle another day.
Basically the deal is that I have a pair of standalone databases that are in
different locations. These databases have a lifespan of 4 Days. Yup after
4 days the information contained in these things is useless, and we'll throw
them away and never use of even have to refer to them again. The deal is
that the customer wants to synchronize the data in these things at the end
of each day, so that a record created in one of em would have migrated to
the other at the end of the day. There is not network, no internet, no
nothing, other than a Sneaker Net at the end of the day to connect them.
So my Plan was to start out the databases with one tables Seed value about
1,000,000 ahead of the others. Then at the end of each day link the two
together with a third synchronizer database, and move new records from
hither to yon and vise versa. No problem easy peasy.
However, after running the two append queries Access likes to change the
Autonumber seed to be one higher than the last record that was inserted. I
guess that this isn't that bad as the numbers are still gonna be unique, and
the database(s) doesn't use em for anything else. UNLESS heaven forbid the
customer comes up with a request for a third or fourth database.
So anyway I figured I'll just reset autonumber seed to an appropriate value
after running the Insert queries. This turned out to be more of a problem
than I bargained for. After trying and failing a number of ways to do this
I found something that works, BUT I hate it. I am Automating Access! Yuk
:-( Here is the code I am using.
' ************** Code Follows **************
Private Sub ResetAutoNumberSeed(strDatabaseName As String, _
strTablename As String, _
strColumnName As String, _
Optional lngNewStartValue As Long = 1, _
Optional lngNewIncrement As Long = 1)
' Purpose Re-seed an Access Auto Number field in a Remote database
' Uses Late Binding
'
Dim accDb As Object
On Error GoTo err_ResetAutoNumberSeed
Set accDb = CreateObject("Access.Application")
accDb.OpenCurrentDatabase strDatabaseName
accDb.Visible = False
' Reset the Seed by running a
accDb.DoCmd.RunSQL "Alter Table " & strTablename & " Alter Column " &
strColumnName _
& " Counter(" & lngNewStartValue & "," &
lngNewIncrement & ")"
accDb.CloseCurrentDatabase
err_ResetAutoNumberSeedResume:
Set accDb = Nothing
Exit Sub
err_ResetAutoNumberSeed:
MsgBox "Error Resetting the Autonumber Seed Value!" & vbCrLf & vbCrLf _
& "Error number: " & Err.Number & vbCrLf _
& "Error Descr: " & Err.Description, vbExclamation, "MyApp"
Resume err_ResetAutoNumberSeedResume
End Sub
' ************** Code Ends **************
Can anyone suggest a better way to do this?
Rdub
couple of Access databases. Yea I know this is a bad practice, but I just
need to get this done so I can live to fight the real battle another day.
Basically the deal is that I have a pair of standalone databases that are in
different locations. These databases have a lifespan of 4 Days. Yup after
4 days the information contained in these things is useless, and we'll throw
them away and never use of even have to refer to them again. The deal is
that the customer wants to synchronize the data in these things at the end
of each day, so that a record created in one of em would have migrated to
the other at the end of the day. There is not network, no internet, no
nothing, other than a Sneaker Net at the end of the day to connect them.
So my Plan was to start out the databases with one tables Seed value about
1,000,000 ahead of the others. Then at the end of each day link the two
together with a third synchronizer database, and move new records from
hither to yon and vise versa. No problem easy peasy.
However, after running the two append queries Access likes to change the
Autonumber seed to be one higher than the last record that was inserted. I
guess that this isn't that bad as the numbers are still gonna be unique, and
the database(s) doesn't use em for anything else. UNLESS heaven forbid the
customer comes up with a request for a third or fourth database.
So anyway I figured I'll just reset autonumber seed to an appropriate value
after running the Insert queries. This turned out to be more of a problem
than I bargained for. After trying and failing a number of ways to do this
I found something that works, BUT I hate it. I am Automating Access! Yuk
:-( Here is the code I am using.
' ************** Code Follows **************
Private Sub ResetAutoNumberSeed(strDatabaseName As String, _
strTablename As String, _
strColumnName As String, _
Optional lngNewStartValue As Long = 1, _
Optional lngNewIncrement As Long = 1)
' Purpose Re-seed an Access Auto Number field in a Remote database
' Uses Late Binding
'
Dim accDb As Object
On Error GoTo err_ResetAutoNumberSeed
Set accDb = CreateObject("Access.Application")
accDb.OpenCurrentDatabase strDatabaseName
accDb.Visible = False
' Reset the Seed by running a
accDb.DoCmd.RunSQL "Alter Table " & strTablename & " Alter Column " &
strColumnName _
& " Counter(" & lngNewStartValue & "," &
lngNewIncrement & ")"
accDb.CloseCurrentDatabase
err_ResetAutoNumberSeedResume:
Set accDb = Nothing
Exit Sub
err_ResetAutoNumberSeed:
MsgBox "Error Resetting the Autonumber Seed Value!" & vbCrLf & vbCrLf _
& "Error number: " & Err.Number & vbCrLf _
& "Error Descr: " & Err.Description, vbExclamation, "MyApp"
Resume err_ResetAutoNumberSeedResume
End Sub
' ************** Code Ends **************
Can anyone suggest a better way to do this?
Rdub