Timo van Esch
Registered User.
- Local time
- Today, 20:53
- Joined
- Oct 2, 2013
- Messages
- 18
Hi,
It's been a while since I needed this forum. I learned a great deal browsing around, gave some comments and continued developing for the company I work for.
Now I've stumbled upon a whole new problem: All morning I've been looking to create a simple pass-through query in Access.
Problem: through ConnectionString I am able to TRUNCATE a table, but I don't get the INSERT command to work.
I have this to wrap my SQL statement in:
This is my first command:
This one works, no problem. That means the connection string is ok; I make a connection with the MySQL server and delete all contents.
Then I use the same function to insert data, and that fails with a 3146 error "ODBC--Call failed."
All the SQL statements below fail with the same error:
COLUMN_30 is the primary key in MySQL, that's why I try to insert this one. When I run it in ACCESS as an append query I have no problems. But when I try to run it through either VBA or through query builder as a passthrough query, it fails.
When I do the same with a usual append query and a linked ODBC MySQL table, it has no problems. Only when I try to make it work on server-side, it fails.
Has anyone experience with passthrough queries?
And would you be so kind to help me out with this one?
With kind regards,
Timo
It's been a while since I needed this forum. I learned a great deal browsing around, gave some comments and continued developing for the company I work for.
Now I've stumbled upon a whole new problem: All morning I've been looking to create a simple pass-through query in Access.
Problem: through ConnectionString I am able to TRUNCATE a table, but I don't get the INSERT command to work.
I have this to wrap my SQL statement in:
Code:
Function Test_SQL_PassThrough(ByVal ConnectionString As String, _
ByVal SQL As String, _
Optional ByVal QueryName As String)
On Error GoTo Err_Handler
Dim dbs As DAO.Database
Dim qdf As DAO.QueryDef
Set dbs = CurrentDb
Set qdf = dbs.CreateQueryDef
With qdf
.Name = QueryName
.Connect = ConnectionString
.SQL = SQL
.ReturnsRecords = (Len(QueryName) > 0)
If .ReturnsRecords = False Then
.Execute
Else
If Not IsNull(dbs.QueryDefs(QueryName).Name) Then dbs.QueryDefs.Delete QueryName
dbs.QueryDefs.Append qdf
End If
.Close
End With
Set qdf = Nothing
Set dbs = Nothing
Exit_Handler:
Exit Function
Err_Handler:
MsgBox Errors.Count & Err.Source & Err.HelpContext & " Error " & Err.Number & vbCrLf & Err.Description & vbCrLf, , "ERROR"
Resume Exit_Handler
End Function
Code:
Test_SQL_PassThrough(ConnString, "TRUNCATE tbl_name;")
Then I use the same function to insert data, and that fails with a 3146 error "ODBC--Call failed."
All the SQL statements below fail with the same error:
Code:
INSERT INTO tbl_name_mysql ( COLUMN_30 ) SELECT tbl_name_access.COLUMN_30 FROM tbl_name_access LIMIT 5;
INSERT INTO tbl_name_mysql ( COLUMN_30 ) SELECT COLUMN_30 FROM tbl_name_access LIMIT 5;
INSERT INTO tbl_name_mysql ( COLUMN_30 ) SELECT COLUMN_30 FROM tbl_name_access;
INSERT INTO tbl_name_mysql ( COLUMN_30 ) SELECT COLUMN_30 FROM tbl_name_access LIMIT 5;
INSERT INTO tbl_rpm_FERT ( COLUMN_30 ) SELECT ( COLUMN_30 ) FROM tbl_RPM_FERT2009;
When I do the same with a usual append query and a linked ODBC MySQL table, it has no problems. Only when I try to make it work on server-side, it fails.
Has anyone experience with passthrough queries?
And would you be so kind to help me out with this one?
With kind regards,
Timo