Option Explicit
' ----------------------------------------------------------
' ODBC API Declarations
' ----------------------------------------------------------
' basic ODBC Declares
Declare Function SQLAllocEnv Lib "odbc32.dll" (env As Long) As Integer
Declare Function SQLFreeEnv Lib "odbc32.dll" (ByVal env As Long) As Integer
Declare Function SQLAllocConnect Lib "odbc32.dll" (ByVal env As Long, _
hDbc As Long) As Integer
Declare Function SQLConnect Lib "odbc32.dll" (ByVal hDbc As Long, _
ByVal Server As String, ByVal serverlen As Integer, _
ByVal uid As String, ByVal uidlen As Integer, ByVal pwd As String, _
ByVal pwdlen As Integer) As Integer
Declare Function SQLFreeConnect Lib "odbc32.dll" (ByVal hDbc As Long) _
As Integer
Declare Function SQLDisconnect Lib "odbc32.dll" (ByVal hDbc As Long) _
As Integer
Declare Function SQLAllocStmt Lib "odbc32.dll" (ByVal hDbc As Long, _
hStmt As Long) As Integer
Declare Function SQLFreeStmt Lib "odbc32.dll" (ByVal hStmt As Long, _
ByVal EndOption As Integer) As Integer
Declare Function SQLExecDirect Lib "odbc32.dll" (ByVal hStmt As Long, _
ByVal sqlString As String, ByVal sqlstrlen As Long) As Integer
Declare Function SQLNumResultCols Lib "odbc32.dll" (ByVal hStmt As Long, _
NumCols As Integer) As Integer
Declare Function SQLFetch Lib "odbc32.dll" (ByVal hStmt As Long) As Integer
Declare Function SQLGetData Lib "odbc32.dll" (ByVal hStmt As Long, _
ByVal Col As Integer, ByVal wConvType As Integer, ByVal lpbBuf As String, _
ByVal dwbuflen As Long, lpcbout As Long) As Integer
Declare Function sqlError Lib "odbc32.dll" Alias "SQLError" (ByVal env As _
Long, ByVal hDbc As Long, ByVal hStmt As Long, ByVal SQLState As _
String, NativeError As Long, ByVal Buffer As String, ByVal Buflen As _
Integer, OutLen As Integer) As Integer
Declare Function SQLSetConnectOption Lib "odbc32.dll" (ByVal hDbc&, _
ByVal fOption%, ByVal vParam&) As Integer
Declare Function SQLSetStmtOption Lib "odbc32.dll" (ByVal hStmt&, _
ByVal fOption%, ByVal vParam&) As Integer
' misc Constants
Public Const sqlChar = 1
Public Const sqlMaxMsgLen = 512
Public Const sqlFetchNext = 1
Public Const sqlFetchFirst = 2
Public Const sqlStillExecuting = 2
Public Const sqlODBCCursors = 110
Public Const sqlConcurrency = 7
Public Const sqlCursorType = 6
' -- ODBC Commands
Public Const ODBC_ADD_DSN = 1&
Public Const ODBC_CONFIG_DSN = 2&
Public Const ODBC_REMOVE_DSN = 3&
Public Const ODBC_ADD_SYS_DSN = 4&
Public Const ODBC_CONFIG_SYS_DSN = 5&
Public Const ODBC_REMOVE_SYS_DSN = 6&
Public Const ODBC_REMOVE_DEFAULT_DSN = 7&
' -- ODBC Error Codes
Public Const ODBC_ERROR_GENERAL_ERR = 1
Public Const ODBC_ERROR_INVALID_BUFF_LEN = 2
Public Const ODBC_ERROR_INVALID_HWND = 3
Public Const ODBC_ERROR_INVALID_STR = 4
Public Const ODBC_ERROR_INVALID_REQUEST_TYPE = 5
Public Const ODBC_ERROR_COMPONENT_NOT_FOUND = 6
Public Const ODBC_ERROR_INVALID_NAME = 7
Public Const ODBC_ERROR_INVALID_KEYWORD_VALUE = 8
Public Const ODBC_ERROR_INVALID_DSN = 9
Public Const ODBC_ERROR_INVALID_INF = 10
Public Const ODBC_ERROR_REQUEST_FAILED = 11
Public Const ODBC_ERROR_INVALID_PATH = 12
Public Const ODBC_ERROR_LOAD_LIB_FAILED = 13
Public Const ODBC_ERROR_INVALID_PARAM_SEQUENCE = 14
Public Const ODBC_ERROR_INVALID_LOG_FILE = 15
Public Const ODBC_ERROR_USER_CANCELED = 16
Public Const ODBC_ERROR_USAGE_UPDATE_FAILED = 17
Public Const ODBC_ERROR_CREATE_DSN_FAILED = 18
Public Const ODBC_ERROR_WRITING_SYSINFO_FAILED = 19
Public Const ODBC_ERROR_REMOVE_DSN_FAILED = 20
Public Const ODBC_ERROR_OUT_OF_MEM = 21
Public Const ODBC_ERROR_OUTPUT_STRING_TRUNCATED = 22
'API Command to create a Data Source Name, not used in this example
Public Declare Function SQLCreateDataSource Lib "odbccp32.dll" (ByVal hwnd&, ByVal lpszDS$) As Boolean
'API to modify/Edit/Create a Data Source Name
Public Declare Function SQLConfigDataSource Lib "odbccp32.dll" (ByVal hwnd As Long, ByVal fRequest As Integer, ByVal lpszDriver As String, ByVal lpszAttributes As String) As Boolean