Posts

Showing posts with the label excel-2010

VBA ADO SQL too few parameters

Image
Clash Royale CLAN TAG #URR8PPP VBA ADO SQL too few parameters I asked this question before but I am still stuck and unable to put parameters inside a SQL query. Public Function testInsert(tableName As String, dType As String, role As String, FiscalYear As String) Dim cmd As ADODB.Command Dim conn As ADODB.connection Dim prm As ADODB.Parameter Dim connectionString As String Dim SQL As String Set conn = New ADODB.connection Set cmd = New ADODB.Command DBPath = "pathtofile.xlsm" connectionString = "Provider=MSDASQL.1;DSN=Excel Files;DBQ=" & DBPath &";HDR=Yes';" SQL = "INSERT INTO [" & tableName & "$] ([Year], [Type], [role]) VALUES (p1, p2, p3)" 'Open connection conn.Open connectionString 'Set command text cmd.CommandText = SQL cmd.CommandType = adCmdText 'Set connection cmd.ActiveConnection = conn 'Set paramters in SQL query Set prm = cmd.CreateParameter("p1...