Mike Sherrill <MS*************@compuserve.com> wrote in message news:<gh********************************@4ax.com>. ..
On 4 Dec 2003 08:45:06 -0800, pi******@yahoo.fr (JMCN) wrote:
yes there is a primary key and a unique index defined (yes(no
duplicates) on the ET number field in Exception Tracking table. I
have created many tests to figure out if i could append the data
without the primary key and index on ET number field, which did work.
Are you saying that you cannot append the data unless you drop the
primary key constraint? If so, that would seem to be your
problem--you're not providing suitable values for the primary key.
the reason why there is the primary key and index on ET number because
it suppose to be the next sequence number.
Are you providing the next sequence number?
Yes I cannot append the data unless if I drop the primary key
constraints. The values are the next sequence number that is written
in a routine:
Public Function GetNextTrackingNumber() As Long
Dim Dbe As Database
Dim rst As Recordset
Set Dbe = DBEngine(0)(0)
Set rst = Dbe.OpenRecordset("SELECT * FROM [Exception Tracking] ORDER
BY [ET Number] ASC")
If rst.RecordCount > 0 Then
rst.MoveLast
GetNextTrackingNumber = rst![ET Number] + 1
Else
GetNextTrackingNumber = 100000
End If
rst.Close
Dbe.Close
End Function
what i don't understand is if one can add a sequence number by means
of the Function GetNextTrackingNumber, then why can i not add it in my
code below?
Set dbsEtrack = CurrentDb
'Set rstET = ("Exception Tracking")
'step one: delete the tdf("tblImportET")
dbsEtrack.TableDefs.Delete ("tblImportET")
'step two: Create a new TableDef object.
Set tdfNew = dbsEtrack.CreateTableDef("tblImportET")
With tdfNew
.Fields.Append .CreateField("ET LN Shortname", dbText, 16)
.Fields.Append .CreateField("ET Amount", dbCurrency)
.Fields.Append .CreateField("ET EC Code", dbText, 120)
''GetNextTrackingNumber 'call function in the Etrack routine module
'.Fields.Append.CreateField("ET Number", dbLong) = rstET![ET
Number] + 1
'cannot append when it is a primary key and is indexed
dbsEtrack.TableDefs.Append tdfNew
End With
dbsEtrack.TableDefs.Refresh
dbsEtrack.Execute "INSERT INTO [tblImportET] SELECT * FROM
[qryBMODReportWeekday] ", dbFailOnError
so if you have any idea, it would be definitely appreciated!!!
merci - thanks! jung