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 June 12th, 2006, 07:05 PM
Registered User
 
Join Date: Jun 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Granular control in uploading data to SQL 2000

:)

I have a excel spreadsheet that is uploading data to tables in a SQL database.

I need more grandular control:

Based on a date say 1/01/2007 I want to be able to upload a range of excel cells with data to an offset position in the database columns.

Example: if 1/01/2007 upload to column 12 thru column 24 in the database and if 1/01/2008 upload data to columns 25 thru columns 37.

Any similar sample of code or any discerning thoughts would be most appreciated.

Thanks so much for your help ahead of time.

Henry

 
Old June 26th, 2006, 02:24 PM
Authorized User
 
Join Date: Mar 2006
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
Default

sounds possible, are the columns fixed, or is there criteria which is needs to be tested to see if it needs uploading

 
Old June 26th, 2006, 04:46 PM
Registered User
 
Join Date: Jun 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

:)Actually I got it figured out ...but thanks so much for responding.

I had to upload hundreds of cells vertically which was simple just a row at a time but this one caught me a little off guard but it works very well and is robust code.

This will upload a range of cells in a horizonal motif


Const ConnectionString As String = _
                "Provider=SQLOLEDB.1;" & _
                "Data Source=servername;" & _
                 "Initial Catalog=databasename;" & _
                 "User ID=username;" & _
                 "Password=userpassword;"

    Dim Connection As ADODB.Connection
    Set Connection = New ADODB.Connection
    Connection.ConnectionString = ConnectionString
    Dim SQLstr As String
    Dim Recordset As Recordset
    Dim rng0 As Range
    Dim rng As Range
    Dim r As Variant
    Dim rngCol As Range
    Dim wksExpense As Worksheet
    Dim rngSR As Range
    Dim rngUploaded As Range
    Dim rngCO As Range
    Set wksExpense = ThisWorkbook.Worksheets("Expense Forecast")
    Set rngSR = wksExpense.Range("A3")
    Set rngUploaded = wksExpense.Range("B3")
    Set rngCO = wksExpense.Range("C3")


     Set rng = wksExpense.Range("J1").Resize(2, 36)

     Connection.Open


     For Each rngCol In rng.Columns



            SQLstr = "INSERT INTO tSrNew(SRNo, DateUpload, ChgOrderNo, EMONTH, EAMOUNT)" & _
            " VALUES ('" & rngSR.Value & "', '" & rngUploaded.Value & "', '" & rngCO.Value & "', '" & rngCol.Cells(1).Value & "', " & rngCol.Cells(2).Value & ")"

            'MsgBox SQLstr


           Connection.Execute (SQLstr)



    Next

   If (Connection.State = ObjectStateEnum.adStateOpen) Then
      Connection.Close
    End If







Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL Server 2000 data fetching overrideme VB Databases Basics 0 April 21st, 2008 09:05 AM
How to export SQL Server 2000 data in kwilliams XML 13 November 30th, 2005 10:20 AM
Export data in conditions - SQL server 2000 minhpx SQL Server 2000 1 March 19th, 2005 01:45 AM
Data Shaping In SQL Server 2000 nidgep SQL Server ASP 5 August 29th, 2003 03:30 PM
Return Data Structure in SQL Server 2000 kasie SQL Server 2000 1 June 29th, 2003 06:50 AM





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