+ Reply to Thread
Results 1 to 7 of 7

it just uploading the wds_id column but it is not uploading other columns please help me

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-01-2014
    Location
    Mysore
    MS-Off Ver
    Excel 2007
    Posts
    379

    it just uploading the wds_id column but it is not uploading other columns please help me

        Function esc(txt)
            'Will replace the 's with MySQL-friendly characters
            esc = Trim(Replace(txt, "'", "\'"))
        End Function
    Sub upload()
    
    '====================================
    '= Code made by :                   =
    '= Michael Clermont & The Interwebs =
    '= 04/04/2011 - Version 1.00        =
    '====================================
    'INSTRUCTIONS                       =
    '==================================================================================================
    ' 1. Make sure you have Microsoft ActiveX Data Objects Library enabled (Tool > References).       =
    ' 2. Download the latest MySQL ODBC Driver (Google search).                                       =
    ' 3. Change the settings below and select the proper driver in this case "MySQL ODBC 5.1 Driver". =
    ' 4. Copy the required data into your form and press the button.                                  =
    '==================================================================================================
    
    '------------------------------------------------------------------------------
    'Variable declarations
    '------------------------------------------------------------------------------
    
    Dim conn As New ADODB.Connection
    Dim server_name As String
    Dim database_name As String
    Dim user_id As String
    Dim password As String
    Dim database_table As String
    Dim count As Integer
    Dim cell As String
    Dim cell_1 As String
    Dim cell_2 As String
    Dim count_2 As Integer
    Dim count_3 As Integer
    
    '------------------------------------------------------------------------------
    'Settings
    '------------------------------------------------------------------------------
    
    server_name = "192.168.1.200" 'Enter your server IP here - if running from a local computer use 127.0.0.1
    database_name = "wds" 'Enter your database name here
    user_id = "root" 'Enter your database user here
    password = "bmx1" 'Enter your database user password here
    database_table = "tblprod_agr_006" 'Enter database table name
    
    '------------------------------------------------------------------------------
    'Initiate database connection
    '------------------------------------------------------------------------------
    
    'Specify your driver below
    
    Set conn = New ADODB.Connection
    conn.Open "DRIVER={MySQL ODBC 5.2 Unicode Driver}" _
    & ";SERVER=" & server_name _
    & ";DATABASE=" & database_name _
    & ";UID=" & user_id _
    & ";PWD=" & password _
    & ";OPTION=16427" ' Option 16427 = Convert LongLong to Int: This just helps makes sure that large numeric results get properly interpreted
    ' & ";DSN=" & DSN_
    'MsgBox "Server connection OK" 'Debug
    
    '------------------------------------------------------------------------------
    'Assign values to global variables
    '------------------------------------------------------------------------------
    
    aWidth = WorksheetFunction.CountA(Range("A1:FA1")) 'Finds the width of the table - if you have more columns than that, just extend the range
    aheight = WorksheetFunction.CountA(Range("A1:A65536")) - 1 'Finds the height of the table, minus the field names - if you have more rows than that, just extend the range
    count = 0 'Will be used throughout the macro as a counter
    count_2 = 0 'Will be used throughout the macro as a counter
    count_3 = 0 'Will be used throughout the macro as a counter
    
    '------------------------------------------------------------------------------
    'Populate the table row
    '------------------------------------------------------------------------------
    ReDim array_fields(aWidth)
    'This will populate INTO what the VALUES will go for the whole upload
    Do Until count = aWidth
        count = count + 1 'Set the count to be used in the array and increment it for the the Do
       cell = Worksheets("production_data").Cells(1, count).Value
        array_fields(count) = cell
    Loop
    
    'This is not necessary, but is done for better code comprehension (and to avoid any problems later on)
    count = 0 'reset the counter
    
    '------------------------------------------------------------------------------
    'Get the data and store it within an array
    '------------------------------------------------------------------------------
    ReDim array_values(aheight)
    Do Until count = aheight
    
        'repopulate the first cell
        If IsNumeric(array_fields(count_2)) Then
            strQuote = vbNullString
        Else
            strQuote = "'"
        End If
        cell = strQuote & esc(array_fields(count_2)) & strQuote
    
        'Populate the cell value
      '  Do Until count_3 = aWidth
       '   If IsNumeric(array_fields(count_2, (count_2 + 1))) Then
        '        strQuote = vbNullString
         '   Else
          '      strQuote = "'"
          '  End If
          '  cell_2 = cell_2 & ", " & strQuote & esc(array_fields(count_2, (count_3 + 1))) & strQuote
          '  count_3 = count_3 + 1
        'Loop
    
        'MsgBox (cell) 'debug
        'MsgBox (cell_2) 'debug
    
        'Run the query
        strSQL = "INSERT INTO " & database_table & " (" & cell_1 & ") VALUES (" & cell_2 & ")"
        'MsgBox (strSQL) 'debug
        conn.Execute (strSQL) 'execute the above query
    
        'Reset the variables for the loop
        count_2 = count_2 + 1
        count = count + 1
        count_3 = 1
        cell_2 = ""
    
    
    Loop
    
    'Close the DB connection
    conn.Close
    Set conn = Nothing
    
    MsgBox ("Upload finished")
    
    'This is not necessary, but is done for better code comprehension (and to avoid any problems later on)
    count = 0 'clean up the variables, just in case
    count_2 = 0 'clean up the variables, just in case
    
    End Sub

  2. #2
    Registered User
    Join Date
    09-13-2012
    Location
    Mumbai
    MS-Off Ver
    Excel 2013
    Posts
    9

    Re: it just uploading the wds_id column but it is not uploading other columns please help

    Try this:
    HTML Code: 

  3. #3
    Forum Contributor
    Join Date
    03-01-2014
    Location
    Mysore
    MS-Off Ver
    Excel 2007
    Posts
    379

    Re: it just uploading the wds_id column but it is not uploading other columns please help

    Subscription out of range run time error '9'

     '------------------------------------------------------------------------------
    'Get the data and store it within an array
    '------------------------------------------------------------------------------
    ReDim array_values(aheight)
    Do Until count = aheight
    
        'repopulate the first cell
        If IsNumeric(array_fields(count_2)) Then            -----getting error here 
            strQuote = vbNullString
        Else
            strQuote = "'"
        End If
        cell = strQuote & esc(array_fields(count_2)) & strQuote
    
        'Populate the cell value
        Do Until count_3 = aWidth
         If IsNumeric(array_fields(count_2, (count_2 + 1))) Then
                strQuote = vbNullString
            Else
                strQuote = "'"
            End If
            cell_2 = cell_2 & ", " & strQuote & esc(array_fields(count_2, (count_3 + 1))) & strQuote
            count_3 = count_3 + 1
        Loop
    
        'MsgBox (cell) 'debug
        'MsgBox (cell_2) 'debug
    
        'Run the query
        strSQL = "INSERT INTO " & database_table & " (" & cell_1 & ") VALUES (" & cell_2 & ")"
        'MsgBox (strSQL) 'debug
        conn.Execute (strSQL) 'execute the above query
    
        'Reset the variables for the loop
        count_2 = count_2 + 1
        count = count + 1
        count_3 = 1
        cell_2 = ""
    
    
    Loop
    
    'Close the DB connection
    conn.Close
    Set conn = Nothing
    
    MsgBox ("Upload finished")
    
    'This is not necessary, but is done for better code comprehension (and to avoid any problems later on)
    count = 0 'clean up the variables, just in case
    count_2 = 0 'clean up the variables, just in case
    
    End Sub

  4. #4
    Forum Contributor
    Join Date
    06-24-2005
    Location
    excelliot.com
    MS-Off Ver
    2007
    Posts
    325

    Re: it just uploading the wds_id column but it is not uploading other columns please help

    which line??

  5. #5
    Forum Contributor
    Join Date
    03-01-2014
    Location
    Mysore
    MS-Off Ver
    Excel 2007
    Posts
    379

    Re: it just uploading the wds_id column but it is not uploading other columns please help

    in this line(array_fields)
    please help me out
    one column called wds_id as integer other columns are strings of Character
    '------------------------------------------------------------------------------
    'Get the data and store it within an array
    '------------------------------------------------------------------------------
    ReDim array_values(aheight)
    Do Until count = aheight

    'repopulate the first cell
    If IsNumeric(array_fields(count_2)) Then -----in this line(array_fields)
    strQuote = vbNullString
    Else
    strQuote = "'"
    End If
    cell = strQuote & esc(array_fields(count_2)) & strQuote
    Last edited by baig123; 05-20-2014 at 02:04 AM. Reason: paragraph

  6. #6
    Forum Contributor
    Join Date
    06-24-2005
    Location
    excelliot.com
    MS-Off Ver
    2007
    Posts
    325

    Re: it just uploading the wds_id column but it is not uploading other columns please help

    change this lines from

    HTML Code: 
    to

    HTML Code: 

  7. #7
    Forum Contributor
    Join Date
    03-01-2014
    Location
    Mysore
    MS-Off Ver
    Excel 2007
    Posts
    379

    Re: it just uploading the wds_id column but it is not uploading other columns please help

    i am getting same Error here subscription out of range(Run time error :'9') please help me out
    'repopulate the first cell
    'If IsNumeric(array_fields(count_2)) Then -----in this line(array_fields) 
    'strQuote = vbNullString
    'Else
    strQuote = "'"
    'End If
    cell = strQuote & esc(array_fields(count_2)) & strQuote
    --->now Getting error here in this line

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Uploading xml file
    By Alf in forum Suggestions for Improvement
    Replies: 3
    Last Post: 02-10-2014, 01:39 AM
  2. Uploading PDF with FTP using VBA
    By bpenn in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-27-2012, 06:15 AM
  3. Uploading?
    By supersohe in forum Excel General
    Replies: 2
    Last Post: 08-10-2007, 07:15 AM
  4. Uploading an XML Doc in Excel
    By ct60 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-22-2006, 09:05 PM
  5. [SOLVED] FTP uploading
    By Mike Archer in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-26-2006, 09:10 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1