Results 1 to 5 of 5

Thread: Stupid Access and INSERT

  1. #1

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945

    Stupid Access and INSERT

    I've tried doing a search for a solution, but to no avail.

    I have a simple insert statement that should write to an Access database. It's only one table and all the datatypes are text.

    VB Code:
    1. CN.Execute "INSERT INTO Part_Info ( ID, Man, Cur, Desc )" & _
    2.             "Values('" & arrAdd(0) & "', '" & arrAdd(1) & "', '" & arrAdd(2) & "', '" & arrAdd(3) & "')"

    I copied my code from another project exactly and simply changed all the names of the variables.

    For some reason it will not take all of these values and says there is something wrong with my insert statement. If I take out the last 2 it works. If I insert the PK (the ID field) and then do an update, I can get the update to work for Man and Cur, but I have to update them seperately. This is driving me absolutely mad. Please help me.
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  2. #2
    Hyperactive Member
    Join Date
    Aug 2002
    Posts
    416
    Create the statement in Access using their query builder, then goto SQL view and copy and paste the SQL statement it generates for you.

    I had a problem with insert statements as well, it was because of the "values" statement. Never wanted to work. So I just used the sytanx of the access-generated query.

  3. #3
    Hyperactive Member
    Join Date
    Jan 2003
    Location
    Cape Cod, US
    Posts
    292
    Here's a fast way of getting to the source of the matter that I like to use:

    Assign your SQL to a variable, like szSQL = "INSERT ..."

    Set a break point after you assign it and in the immediate window type debug.print szSQL or ? szSQL

    You should see your complete statment. Copy and paste it as a new query in Access and run it there to see what's going on...

    Just from looking it it it looks OK except you may need a space before VALUES

  4. #4
    Addicted Member
    Join Date
    Jul 2002
    Location
    BC, Canada
    Posts
    152

    Re: Stupid Access and INSERT

    Originally posted by ober5861
    I've tried doing a search for a solution, but to no avail.

    VB Code:
    1. CN.Execute "INSERT INTO Part_Info ( ID, Man, Cur, Desc )" & _
    2.             "Values('" & arrAdd(0) & "', '" & arrAdd(1) & "', '" & arrAdd(2) & "', '" & arrAdd(3) & "')"
    Well, there's probably two things here, but one is causing your main error.

    1) numbered fields complain when you have the single quotes around it, such as Num = '3' whereas the SQL usually wants Num = 3. For text fields, use the single quotes. For numbers, without.

    2) be careful on inserting a specific PK. If the number is autogenerated, you don't even have to insert it at all (should be inserted automatically..)

    I could be wrong, but that's what I'd try. Also, Fungi has a good idea of testing out your sql statement in access.

    Destined

  5. #5

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    ok... nevermind... turns out it was the damn names of the fields.
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

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