Results 1 to 7 of 7

Thread: Strange error when adding a record...

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 1999
    Location
    West Hartford, CT, USA
    Posts
    42
    I'm currently using VB 6.0 and MySQL server. I'm trying to add a record to a table and getting a strange error. I'm using the following code:

    selStmt = "SELECT * FROM customer;"
    recset1.Open selStmt, cnn1, adOpenKeyset, adLockPessimistic
    With recset1
    .AddNew
    .Fields("cust_name") = CustomerName
    .Fields("contact_name") = ContactName
    .Update
    .Requery
    .MoveLast
    .Close
    End With

    If the data for either field exceeds 14 characters, I get the following error:

    ------
    Run-time error '-2147217887 (80040e21)':

    Errors occurred
    ------

    If I debug, it places me on the ".fields" line for the field in which I exceeded 14 characters.

    Both fields are set up as varchar(40). If I try to add the same data to the table using Access, I don't have any problems at all.

    I'm out of ideas on this, so if anyone has any ideas....

    Thanks!

  2. #2
    New Member
    Join Date
    May 2000
    Location
    Crowthorne UK
    Posts
    14

    Lightbulb

    I found that this error occured when I tried to import a duplicate value into my primary key! DOH!

  3. #3
    Lively Member
    Join Date
    Aug 1999
    Posts
    89
    May be you have add some empty space behind your variable without noticing it?? Try to trim it or write out the variable into a text file. Then use wordpad or others to check if there's any unattended empty space added to your variable.

  4. #4
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844
    loop thru the errors collection to find out the error

    like this:
    for each error in connection.errors
    msgbox error.name
    next

  5. #5
    Lively Member
    Join Date
    Aug 1999
    Posts
    89
    I think if he loops thru the error object, he'll still get the error occur.
    I tried this before. To get the specific error, what i did was to use the query analyser. The last time i got this error in VB, i got another error from query analyser saying my update to the master table failed because of a collision key in the child table.

  6. #6
    Hyperactive Member
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    455

    Hello Clunietp,

    I am a VB5 user, but the description of the error you get on the next way

    Err.Number
    Err.Description

    Michelle.

  7. #7
    Hyperactive Member
    Join Date
    Jun 1999
    Posts
    308
    Try this code, it might give you a detailed message of your error.
    Code:
       Dim MyError As Error
       MsgBox Errors.Count
       For Each MyError In DBEngine.Errors
         With MyError
           MsgBox .Number & " " & .Description
         End With
       Next MyError

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