Advertisement
Guest User

Excel post to DB

a guest
Jan 24th, 2014
540
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. ' Code for Excel VB to post to a db, in this case an access file in the same working directory as the excel.
  2. ' Posts the values in the named cells "loadname, loadpallet, loaddue, etc into the mentioned db columns
  3. ' the ssql string variable doesn't have to be created and con-catted but makes it easier to manage/reuse
  4. Set cn = CreateObject("ADODB.Connection")
  5. dbPath = Application.ActiveWorkbook.Path & "\DLDB.mdb"
  6.  
  7. scn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbPath
  8. dsh = "[" & Application.ActiveSheet.name & "$]"
  9. cn.Open scn
  10. ssql = "INSERT INTO DL ([Load], [Due], [Sent], [Driver], [15min Late], [Minutes Late]) "
  11. ssql = ssql & " VALUES ('" & loadname.Value & ",'" & loaddue.Value & " ','" & loadcheck.Value & "','" & loaddriver & "'," & reallylate & "," & minlate & ")"
  12.  
  13.  
  14.  
  15. cn.Execute ssql
  16. cn.Close
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement