iPhone App Con Sept 27 -- www.iphonedevcon.com
Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
I forgot my password
Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, win occasional prizes given to our best members, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 29th, 2008, 03:24 PM
Registered User
 
Join Date: Aug 2008
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Multiple SQL Statements from Excel to Access

Hello All and thanks for the help in advance -

The module that I am working on is meant to update an Access db by keying off of multiple fields in an excel sheet that will be variable. I am fine with the db connection and creating a sql string in VBA though I do not know the best way to either loop/execute a varying number of similar update statements. I have included a copy of the code that I have been working with below (some parts of my experiments are included) Thanks and please let me know if i need provide any futher information.



Sub UpdateSomeRecordsADO()
Dim cnn As ADODB.Connection
Dim UpdCommand As ADODB.Command
Dim dbstrg As String
Dim UpdStrg As String

    dbstrg = ""
    dbstrg = dbstrg & "O:\AP\2008\testdb.mdb"
' dbstrg = dbstrg & Cells(2, 12)
' dbstrg = dbstrg & "\North American "
' dbstrg = dbstrg & Cells(2, 11)
' dbstrg = dbstrg & ".mdb"

    '' Open the connection.
    Set cnn = New ADODB.Connection
    cnn.Provider = "Microsoft.Jet.OLEDB.4.0"
    cnn.Open dbstrg

    '' Set the command text.
    Set UpdCommand = New ADODB.Command
    Set UpdCommand.ActiveConnection = cnn

    '' - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    UpdStrg = ""
    UpdStrg = UpdStrg & "UPDATE [Sheet1] SET [Paid] = 'Confirmed' WHERE [Acct] = 00003 AND [T/D] = 20080512 AND [B/S] = 1 AND [Price] = 1388.25"

' vtSql = vtSql & " UPDATE " & "Sheet1"
' vtSql = vtSql & " SET Salaryx= 24680"
' vtSql = vtSql & " WHERE Namex='Jennings'"

    With UpdCommand
        .CommandText = UpdStrg
        .CommandType = adCmdText
        .Execute
    End With
' Loop
'Range("Q2").Select

 ' Do
 ' UpdCommand.Execute
 ' ActiveCell.Offset(1, 0).Select
 ' Loop Until IsEmpty(ActiveCell.Offset(0, -16))


    '' Close the connections and clean up.
    cnn.Close
    Set UpdCommand = Nothing
    Set cnn = Nothing
End Sub


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old September 8th, 2008, 11:54 PM
Registered User
 
Join Date: Sep 2008
Location: London, , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi aabnormal,
So you wish to extract data from Excel and enter it into an MS Access database. The database connection code is fine. I can see you wish to extract it from within an MS Excel spreadsheet using the Range, however it's not clear what cells you wish to extract it from.
If you write what you are trying to do in pseudo code i will post the actual VBA code implementation.

Jack

Courtesy of http://www.OfficeSoftworks.co.uk
and http://www.OfficeSoftworks.com

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple LIKE statements melkin MySQL 3 December 17th, 2008 02:38 PM
Multiple IIF statements Corey Access 1 November 16th, 2006 04:25 PM
how to get multiple sql statements in vb.net pascalgeuze VB Databases Basics 2 April 8th, 2004 09:01 AM
executing multiple statements jae_green PHP Databases 1 July 7th, 2003 02:19 PM
Multiple Insert Statements tp194 Classic ASP Databases 8 June 11th, 2003 01:26 AM



All times are GMT -4. The time now is 03:45 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
© 2010 Wiley Publishing, Inc