Article ID: 154046
Article Last Modified on 7/13/2004
Option Explicit
Private Declare Function SQLAllocStmt Lib "odbc32.dll" _
(ByVal hdbc&, phstmt&) As Integer
Private Declare Function SQLExecDirect Lib "odbc32.dll" _
(ByVal hstmt&, ByVal szSqlStr$, ByVal cbSqlStr&) As Integer
Private Sub Command1_Click()
Dim cn As rdoConnection
Set cn = rdoEnvironments(0).OpenConnection( _
dsName:="MyServer", _
Prompt:=rdDriverNoPrompt, _
ReadOnly:=False) 'get hDbc
Dim rv As Integer 'return value
Dim lhStmt As Long 'hStmt
Dim szSql As String 'SQL string
szSql = "Select * into newtable from titles" 'create table SQL
rv = SQLAllocStmt(cn.hdbc, lhStmt) 'allocate a
statement
Debug.Print GetRetCodeText(rv) 'print return value
'text
rv = SQLExecDirect(lhStmt, szSql, Len(szSql)) 'execute the SQL
Debug.Print GetRetCodeText(rv) 'print return value
'text
End Sub
Private Function GetRetCodeText(retcode As Integer)
'get the return value text using ODBC32.TXT constants
Dim x As String
Select Case retcode
Case -1: x = "SQL_ERROR"
Case -2: x = "SQL_INVALID_HANDLE"
Case 100: x = "SQL_NO_DATA_FOUND"
Case 0: x = "SQL_SUCCESS"
Case 1: x = "SQL_SUCCESS_WITH_INFO"
End Select
GetRetCodeText = x
End Function
NOTE: You will need to change the DSN to match yours before continuing.
Additional query words: rdoConnection Execute kbVBp500 kbVBp400 kbdse kbDSupport kbVBp
Keywords: kbhowto KB154046