MS Excel VBA and SQL – problem with INSERT and UPDATE command
Could somebody help me with a little (?) problem?
I need to construct a procedure that should connect MS Access database and INSERT or UPDATE a data record into a table.
I know, SELECT statements are going very well there by using functions supported by XLODBC.xla. In Help there is written that INSERT, UPDATE or DELETE statements are also supported.
But I don’t know, which functions and syntax are needed.
In the case of SELECT statements I use following procedure (a simple example):
strQuery = “SELECT * FROM users WHERE name = ‘Tom’” ‘specifying of the SQL expression
strDatabaseName = "Nabidky" ‘specifying of the name of the database connection
intChan = SQLOpen("DSN=" & strDatabaseName) ‘specifying of the connection ID
SQLExecQuery intChan, strQuery
Set output = Worksheets("Sheet1").Range("A10")
SQLRetrieve intChan, output, , , True
SQLClose intChan
As far as INSERT, UPDATE or DELETE I think that first four lines should be the same (with an appropriate SQL expression in strQuery). But what else? How to continue? Using them “only” I haven’t succeed.
I haven’t found anything useful in MS Help.
Thank you very much for YOUr Help.
Excuse my pure English, pleas.
Tomas
Could somebody help me with a little (?) problem?
I need to construct a procedure that should connect MS Access database and INSERT or UPDATE a data record into a table.
I know, SELECT statements are going very well there by using functions supported by XLODBC.xla. In Help there is written that INSERT, UPDATE or DELETE statements are also supported.
But I don’t know, which functions and syntax are needed.
In the case of SELECT statements I use following procedure (a simple example):
strQuery = “SELECT * FROM users WHERE name = ‘Tom’” ‘specifying of the SQL expression
strDatabaseName = "Nabidky" ‘specifying of the name of the database connection
intChan = SQLOpen("DSN=" & strDatabaseName) ‘specifying of the connection ID
SQLExecQuery intChan, strQuery
Set output = Worksheets("Sheet1").Range("A10")
SQLRetrieve intChan, output, , , True
SQLClose intChan
As far as INSERT, UPDATE or DELETE I think that first four lines should be the same (with an appropriate SQL expression in strQuery). But what else? How to continue? Using them “only” I haven’t succeed.
I haven’t found anything useful in MS Help.
Thank you very much for YOUr Help.
Excuse my pure English, pleas.
Tomas