insert into sqlserver with autonumber

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mark mestrom
    New Member
    • Jun 2007
    • 2

    insert into sqlserver with autonumber

    Hi all, i have a problem.
    In my access-application i am trying to insert a record in a linked table with resides in a sqlserver 2000 database. However, the primary key in that table is an INT with identity. I would expect that sqlserver automatically determines the next unique primary-key value (increment = 1) but it seems that it doesn't. I get a primary-key violation. Is there a way to insert a record from access in sqlserver when the table has a autonumberfield as a primary-key.

    I use the next statement (of course, i don't specify the primary-key value).

    sqlstring = "INSERT INTO dbo_tblSwitchVe rzoeken (ZakenPartner, EAN, Product, LeverancierID, Invoerder) VALUES (" & sZakenpartnernu mmer & "," & sEancode & ", '" & Left(sProdukt, 1) & "'," & sLeverancier & "," & sIngedienddoor & ")"

    DoCmd.RunSQL sqlstring

    Thans for any suggestions.

    Mark
  • Delerna
    Recognized Expert Top Contributor
    • Jan 2008
    • 1134

    #2
    I don't understand your difficulty, I do it all the time. Are you sure the table was set up that way before you linked to it from access. Try deleting the link and re-linking it

    Comment

    Working...