Results 1 to 7 of 7

Thread: [RESOLVED] db Error with Insert into table command

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    UK, Suffolk
    Posts
    319

    Resolved [RESOLVED] db Error with Insert into table command

    I keep getting the following error message

    -2147217904
    No Value given for one or more required parameters

    The code I am using is as follows

    Dim rs As New ADODB.Recordset

    rs.Open "insert into data_delete(ID,FullName,ShortName,Contact,OwnerCo,Pref,Fax1,Fax2,Telex1,Telex2,Memonic1,Memonic2,Ema il,Groups,CortexAccountNo) Values(DataRange.ID,datarange.Fullname,datarange.shortname,datarange.contact,datarange.OwnerCo,datar ange.Pref,datarange.fax1,datarange.fax2,datarange.telex1,datarange.telex2,datarange.memonic1,dataran ge.menonic2,datarange.Email,datarange.groups,datarange.cortexaccountno)", CONNECTIONSTRING, adOpenDynamic, adLockOptimistic

    The basic idea behind this is to copy a deleted record into another table, but I am only bring across certain fields



    Thanks

  2. #2
    eltiT resU motsuC Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: db Error with Insert into table command

    its your Values.. you are passing in field names and not data..
    you either need to pass in specific data or do a select...

    "INSERT INTO data_delete (ID,Fullname,ShortName) VALUES (1,'John Doe','John')"

    or if you want to use variables

    "INSERT INTO data_delete (ID,Fullname,ShortName) VALUES (" & ID & ",'" & FullName & "','" & ShortName & "')"

    or if you want Fields

    "INSERT INTO data_delete (ID,Fullname,ShortName) VALUES (SELECT ID,FullName,ShortName FROM OTHER TABLE WHERE something = somethingelse)"

    Note: I am not possitive on the SQL for the last one.. its been a while since I have written and insert that selects.. but the idea is there
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: db Error with Insert into table command

    You also have fields broken up in your open statement.

    Take a look. Your database is seeing email as ema
    il

    It is also seeing datarange.Pref as datar ange.Pref

    and it is seeing datarange.menonic2 as dataran ge.menonic2

    Put the whole thing in a string, and pass the string to your recordset object. It makes things easier to read and debug. Example:
    VB Code:
    1. Dim rs As New ADODB.Recordset
    2. Dim sSQL As String
    3. sSQL = "insert into data_delete(ID,FullName,ShortName,Contact,OwnerCo,Pref,Fax1,Fax2,Telex1,"
    4. sSQL = sSQL & "Telex2,Memonic1,Memonic2,Email,Groups,CortexAccountNo) "
    5. sSQL = sSQL & "Values(DataRange.ID,datarange.Fullname,datarange.shortname,datarange.contact,datarange.OwnerCo, "
    6. sSQL = sSQL & "datarange.Pref,datarange.fax1,datarange.fax2,datarange.telex1,datarange.telex2,datarange.memonic1, "
    7. sSQL = sSQL & "datarange.menonic2,datarange.Email,datarange.groups,datarange.cortexaccountno) "
    8. rs.Open sSQL, CONNECTIONSTRING, adOpenDynamic, adLockOptimistic

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    UK, Suffolk
    Posts
    319

    Re: db Error with Insert into table command

    Thanks for your suggestions, but none have worked and I am still get the same problem.

    i need a record from Datarange and insert it in to data_delete. I only want to take certain records from DataRange, but I will take all if thats the only way

    Thanks

  5. #5
    eltiT resU motsuC Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: db Error with Insert into table command

    then u need the select

    if data_delete has just the fields you want to insert into then this will work fine
    (the names have to match...)

    "INSERT INTO data_Delete SELECT ID,FullName,ShortName,Contact FROM DataRange WHERE something = somethingelse"

    if the names dont match then u need to specify the fields

    "INSERT INTO data_Delete (IDfield,xFullName,xShortname,xContact) SELECT ID,FullName,ShortName,Contact FROM DataRange WHERE something = somethingelse"


    understand?
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    UK, Suffolk
    Posts
    319

    Thumbs up Re: db Error with Insert into table command

    [A51g]Static,

    Thank you , that worked using the following code from your suggestion

    "INSERT INTO data_Delete (IDfield,xFullName,xShortname,xContact) SELECT ID,FullName,ShortName,Contact FROM DataRange WHERE something = somethingelse"

    Thanks

    Dan

  7. #7
    eltiT resU motsuC Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: db Error with Insert into table command

    youre welcome!!... (dont forget to mark the thread resolve... Thread Tools>Mark Resolved)
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

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