Results 1 to 5 of 5

Thread: ms access cant append all the records due to key violations

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    586

    ms access cant append all the records due to key violations

    Hi,

    question:

    I would like to catch and handle this error (on Error doesn't catch this type of error)

    How can I catch this error?

    more details:

    I'm running a function that inserts records into a table .

    while something

    mySerial = DMax("serial", "myTable") + 1
    sqlstr = " INSERT INTO myTable ( serial SELECT " & mySerial & "; " )
    docmd.runsql sqlstr

    wend

    On same cases the function halts on "ms access cant append all the records due to key violations".

    Checking this further reveals that the that serial generated is already occupied - probably in the case where another user created a new record between generating mySerial to the point where actually runsql tried to commit the new record insert (?)

  2. #2
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: ms access cant append all the records due to key violations

    Can I see your database?

    There is one more reason this error can happen...

    You get this error message when you try to insert empty strings into a field that has its AllowZeroLength property set to No. Do this

    1. Open your destination table in Design view.
    2. Set the AllowZeroLength property of all text fields to Yes.
    3. Save the changes to the table, and then close the table.

    Try now...
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    586

    Re: ms access cant append all the records due to key violations

    Hi,

    Its a MySQL DB connected using ODBC, however the AllowZeroLength is already set to YES on all text fields.

    Any ideas how to catch this error?

    I would like to do something like on Error goto handleErr and there to display the problmatic record on the form and then to resume the rest of the while loop, this will be a good solution for this issue, but I cannot seem to catch the error at all.

    Thanks!

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    586

    Re: ms access cant append all the records due to key violations

    Anything? Anyone?

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: ms access cant append all the records due to key violations

    Why are you generating the serial yourself, rather than letting the database do it automatically (by using an Identity/AutoNumber/Serial data type) ?

    That would not only take less code, but would also avoid the error and other issues with serial numbers that Identity etc deal with.

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