I'm making a macro to upload data to SQLServer, I want this table and every time you run the macro
- Want to work with Recordset Add The last added row
Sub GetData()
Call RecordsetFromSheet(prueba)
End Sub
Public Function RecordsetFromSheet(ByVal tableName As String)
Dim cn As Object
Dim rs As Object
Dim strCon As String
Dim strSQL, strInput As String
Dim cmd As Object
Opening Connection to SQL Server
Set cn = CreateObject("ADODB.Connection")
cn.ConnectionString = OleDbConnectionString("xxxxx", "xxxx", "xx", "xxxxxxx")
cn.Open
Closing Connection
If CBool(cn.State And adStateOpen) = True Then
cn.Close
Set cn = Nothing
End If
End Function
Function To StringConnection
Function OleDbConnectionString(ByVal Server As String, ByVal Database As String, _
ByVal UserName As String, ByVal Password As String) As String
If UserName = "" Then
OleDbConnectionString = "Provider=SQLOLEDB.1;Data Source=" & Server _
& ";Initial Catalog=" & Database _
& ";Integrated Security=SSPI;Persist Security Info=False;"
Else
OleDbConnectionString = "Provider=SQLOLEDB.1;Data Source=" & Server _
& ";Initial Catalog=" & Database _
& ";User ID=" & UserName & ";Password=" & Password & ";"
End If
End Function