If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > SQL Query and Compare

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-04-11, 06:47
kickbutt kickbutt is offline
Registered User
 
Join Date: Mar 2011
Posts: 1
Post SQL Query and Compare

hi,

I am quite new to working with SQL databases in excel VBA.
I have come up with the following code, which writes a range of cells to a table in a SQL database.
Now i have this working i want to query a different table in the database which will loop through the dataset and compare what is entered in to the cells in excel to make sure they exist in that database before writing the range of cells to the original table (just to add some validation)
I have tried many things and can not get this working so any help at all will be greatly appreciated.

thank you,

ps Code:

Sub SubmitInterchange()

Dim oConn As Object
Dim oRS As Object
Dim sSQL As String

Set oConn = CreateObject("ADODB.Connection")
oConn.Open = "Provider=sqloledb;" & _
"Data Source=GW-SYSPRO-01;" & _
"Initial Catalog=SysproCompany2;" & _
"User Id=****;" & _
"Password=****"


For n = 10 To 109

StockCode = Worksheets("Interchange_Insert").Cells(n, 4).Value
Barcode = Worksheets("Interchange_Insert").Cells(n, 5).Value

If StockCode > 1 Then

MsgBox "StockCode:" & StockCode & " Barcode:" & Barcode & ""
sSQL = "INSERT INTO InvMaster(StockCode, DrawOfficeNum) VALUES ('" & StockCode & "', '" & Barcode & "')"
oConn.Execute sSQL
End If

Next n

oConn.Close
Set oConn = Nothing



End Sub
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On