The code below dies on the OPENRECORDSET method. I have tried all flavors; from the CONNECTION object, DATABASE object, and QUERYDEF object. All else seems to be fine.

The DBInit() is called on Worksheet->Open, and DBClose is called BeforeClose().....

I have verified that the sql as displayed in 'MsgBox sql' is valid, and executes.

==========================================
Public wrkODBC As Workspace
Public conGTSQL As Connection

Sub DBInit()

MsgBox "Open Database"
Set wrkODBC = CreateWorkspace("NewODBCWorkspace", "", "", dbUseODBC)
Set conGTSQL = wrkODBC.OpenConnection("Connection1", _
dbDriverNoPrompt, , _
"ODBC;DSN=Gemtrak SQL 32;UID=dba;PWD=xxxxxxx")

End Sub

Sub DBClose()

MsgBox "Close Database"
conGTSQL.Close
wrkODBC.Close

End Sub

Function DBShipped(loccode As Range, yy As Range, mm As Range)

Dim params As String
Dim gtdb As Database
Dim qdf As QueryDef
Dim rs As Recordset
Dim sql As String

params = "( '" & loccode.Value & "', " & _
" YMD( " & yy.Value & ", " & mm.Value & ", 1 ), " & _
" YMD( " & yy.Value & ", " & Str(Val(mm.Value) + 1) & ", 1 ) ) "

Set gtdb = conGTSQL.Database
sql = "select dba.MemoAnalShipped" & params & " as Shipped from dummy"
MsgBox sql
Set rs = gtdb.OpenRecordset(sql, dbOpenForwardOnly, dbSQLPassThrough, False)
Set qdf = conGTSQL.CreateQueryDef("testquery", sql)
Set rs = qdf.OpenRecordset()
' Set rs = conGTSQL.OpenRecordset("testquery", dbOpenForwardOnly)
' Set rs = conGTSQL.OpenRecordset(sql, dbOpenForwardOnly)
If rs.EOF Then
DBShipped = Null
Else
rs.MoveNext
DBShipped = rs!Shipped
End If

rs.Close

End Function