Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 90301

When I run vba macro nothing happens?

$
0
0

I have the below code in my excel file, but when I run it nothing happens and it doesnt come up in window either.

    GetDataFromADO()

        'Declare variables'
            Dim objMyConn As ADODB.Connection
            Dim objMyCmd As ADODB.Command
            Dim objMyRecordset As ADODB.Recordset

            Set objMyConn = New ADODB.Connection
            Set objMyCmd = New ADODB.Command
            Set objMyRecordset = New ADODB.Recordset

        'Open Connection'
            objMyConn.ConnectionString = "Provider=SQLOLEDB;Password=*******;User ID=*****; Initial 
        Catalog=*******; Data Source=*********************,1433;"
            objMyConn.Open

        'Set and Excecute SQL Command'
            Set objMyCmd.ActiveConnection = objMyConn
            objMyCmd.CommandText = "SELECT wh_id,mst_ship_num, cus_name, car_id, vsl_id,late_ship_dt, 
        load_cmpl, dsp_dt,live, ckin_dt,driver_arr_dte   FROM [dbo].[CXU_ALL_LOAD_CONTROL] WHERE wh_id = 
        'U07S' And dsp_dt = '2019-12-31'"
            objMyCmd.CommandType = adCmdText

        'Open Recordset'
            Set objMyRecordset.Source = objMyCmd
            objMyRecordset.Open

        'Copy Data to Excel'
            ActiveSheet.Range("A5").CopyFromRecordset objMyRecordset

   End Sub

Viewing all articles
Browse latest Browse all 90301

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>