hi there,
I need some help. Please.
I have a command button on my excel spreadsheet called "Add data" that basically just adds data from another spreadsheet onto the next available row.
Here is the code:
Dim cnt As ADODB.Connection
Dim stCon As String, stSQL As String, stSQL2 As String
Dim vaNames As Variant
Dim i As Long
Dim xlCalc As Long
With Application
xlCalc = .Calculation
.Calculation = xlCalculationManual
.EnableEvents = False
.ScreenUpdating = False
End With
vaNames = VBA.Array("RFI_Form.xls")
Set cnt = New ADODB.Connection
For i = 0 To UBound(vaNames)
stCon = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\" & vaNames(i) & ";" & _
"Extended Properties='Excel 8.0;HDR=Yes'"
stSQL = "INSERT INTO [RFILog$] In 'C:\SEP_RFI_Log.xls' 'Excel 8.0;'" & _
"SELECT * FROM [RFIInfo$A1:BI2]"
With cnt
.Open (stCon) 'Open the connection
.Execute (stSQL) 'Execute the SQL-query.
.Close 'Close the connection
End With
stCon = Empty
stSQL = Empty
Next i
Set cnt = Nothing
With Application
.Calculation = xlCalc
.EnableEvents = True
.ScreenUpdating = True
End With
I need to modify it somehow so that it looks through a particular column field (called RFI No) and if the RFI no matches a number already in the spreadsheet, it adds the data to the same row as the RFI No (and not a new row).
Any ideas?
Thanks so much...
I need some help. Please.
I have a command button on my excel spreadsheet called "Add data" that basically just adds data from another spreadsheet onto the next available row.
Here is the code:
Dim cnt As ADODB.Connection
Dim stCon As String, stSQL As String, stSQL2 As String
Dim vaNames As Variant
Dim i As Long
Dim xlCalc As Long
With Application
xlCalc = .Calculation
.Calculation = xlCalculationManual
.EnableEvents = False
.ScreenUpdating = False
End With
vaNames = VBA.Array("RFI_Form.xls")
Set cnt = New ADODB.Connection
For i = 0 To UBound(vaNames)
stCon = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\" & vaNames(i) & ";" & _
"Extended Properties='Excel 8.0;HDR=Yes'"
stSQL = "INSERT INTO [RFILog$] In 'C:\SEP_RFI_Log.xls' 'Excel 8.0;'" & _
"SELECT * FROM [RFIInfo$A1:BI2]"
With cnt
.Open (stCon) 'Open the connection
.Execute (stSQL) 'Execute the SQL-query.
.Close 'Close the connection
End With
stCon = Empty
stSQL = Empty
Next i
Set cnt = Nothing
With Application
.Calculation = xlCalc
.EnableEvents = True
.ScreenUpdating = True
End With
I need to modify it somehow so that it looks through a particular column field (called RFI No) and if the RFI no matches a number already in the spreadsheet, it adds the data to the same row as the RFI No (and not a new row).
Any ideas?
Thanks so much...