Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 29th, 2008, 03:24 PM
Registered User
 
Join Date: Aug 2008
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


 
Old September 8th, 2008, 11:54 PM
Registered User
 
Join Date: Sep 2008
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






Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple LIKE statements melkin MySQL 3 December 17th, 2008 03:38 PM
Multiple IIF statements Corey Access 1 November 16th, 2006 05: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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.