Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 131
  • Last Modified:

Insert all the rows without errors into a database called pipeline.mdb

Hi Everyone I did a loop that checks the records from Excel for errors.  The records with errors go into an errors spreadsheet which I already did, but all the records without error need to be inserted into my database (pipeline.mdb)  
Can you guys help me with this?  Basically the entire row gets inserted into the database...I have an if statment that looks for the rows to be inserted but I don't know what code I can use to actually insert them...
Here's my code but of course it doesn't work.

for i = 1 to 14
    if (errors in the records)then 'pseudocode
    'put records into the excel spreadsheet --this part works, no problem
            'Database records without errors should be inserted into the database, I don't know how to do this?!?
             Dim RS As recordset
            Set CMD.ActiveConnection = Conn      
            CMD.CommandText = "INSERT * INTO COMPANY"
            CMD.CommandType = adCmdText
    End If
Next i
1 Solution
needs to be replaced with
CMD.CommandText = "INSERT INTO COMPANY (Field1, Field2, ...,Fieldn) Values ('" & range("A" & i) & "','" & range("B" & i) & "',",...,",'" & range("N" & i) "')"
or a simpler version:

the format of an insert command is:

INSERT INTO company (<comma delimited list of field names) VALUES (<comma demilited list of field values)

so the following:

INSERT INTO company (name,address,product) VALUES ("Microsoft","One Microsoft Way","software")

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now