'You may wish to set this option
Option Private Module

'global variables
Public odbcWksp As Workspace, odbcConn As Connection

'---
Function makeOdbcConn(strDSN As String, strUsrName As String, strPwd As String) As Boolean
    Set odbcWksp = CreateWorkspace("odbcWksp", strUsrName, strPwd, dbUseODBC)
    On Error Resume Next
    Set odbcConn = odbcWksp.OpenConnection(strDSN, dbDriverNoPrompt)
            If Err.Number > 0 And DBEngine.Errors.count > 0 Then
              If DBEngine.Errors(0).Source Like "ODBC.*" Then
                MsgBox Mid(DBEngine.Errors(0), InStr(DBEngine.Errors(0), "ERROR:") + 7) & "@@", vbExclamation, "Error!"
                makeOdbcConn = False
                Exit Function
              End If
            End If
    On Error GoTo 0
    
    ''this block initializes Jet to use the same Connect string
    'Dim qdf As QueryDef, rst As Recordset
    'Set qdf = CurrentDb.CreateQueryDef("")
    'qdf.Connect = odbcConn.Connect
    'qdf.SQL = "SELECT 'Hello'"
    'Set rst = qdf.OpenRecordset()
    'rst.Close
    'Set rst = Nothing
    
    ''If you have passthrough queries this will set the connect string
    'For Each qdf In CurrentDb.QueryDefs
    '  If qdf.Type = dbQSQLPassThrough Then
    '    qdf.Connect = odbcConn.Connect
    '  End If
    'Next qdf
    
    makeOdbcConn = True
End Function

Sub clearODBCConnect()
    ''note: passwords are stored in the connect string of query defs
    '' this will clear the connect strings of passthrough queries
    'Dim qdf As QueryDef
    'For Each qdf In CurrentDb.QueryDefs
    '  If qdf.Type = dbQSQLPassThrough Then qdf.Connect = "ODBC;"
    'Next qdf
    
    If odbcConn Is Nothing Then Exit Sub
    Set odbcConn = Nothing
End Sub
