Gustav Brock
gustav at cactus.dk
Mon Aug 30 09:02:52 CDT 2004
Hi Scott
Did you try separating the database and querydef objects and/or using
a permanent query?
Dim dbs As Database
Dim qdf As QueryDef
Dim rst As Recordset
GetEmployee = False
Set dbs = CurrentDb
Set qdf = dbs.QueryDef("qdyTemp")
qdf.Connect = "ODBC;DSN=dataconnection;UID=user;PWD=password;DBQ=uxs02;DBA=R;APA=T;PFC=1;TLO=0;"
qdf.SQL = "SELECT surname, given_name FROM employees WHERE employeeno = '" & strEmployeeNo & "';"
Set rst = qdf.OpenRecordset(dbOpenForwardOnly, dbSQLPassThrough)
If rst.EOF <> True Then
GetEmployee = True
strName = Trim(rst!given_name) & " " & Trim(rst!surname)
End If
rst.Close
Set rst = Nothing
qdf.Close
Set qdf = Nothing
Set dbs = Nothing
/gustav
> Why would the following function work the first time it is called
> but hang on subsequent calls? It locks up on the OpenRecordset
> statement. I've tried variations on the OpenRecordset statement
> [such as Set rst = qdf.OpenRecordset()]. This is connecting to an
> Oracle database. Watch for line wrap.
> Public Function GetEmployee(strEmployeeNo As String, ByRef strName As String) As Boolean
> On Error GoTo HandleError
> Dim qdf As QueryDef
> Dim rst As Recordset
> GetEmployee = False
> Set qdf = CurrentDb.CreateQueryDef("")
> qdf.Connect = "ODBC;DSN=dataconnection;UID=user;PWD=password;DBQ=uxs02;DBA=R;APA=T;PFC=1;TLO=0;"
> qdf.SQL = "SELECT surname, given_name FROM employees WHERE employeeno = '" & strEmployeeNo & "';"
> Set rst = qdf.OpenRecordset(dbOpenForwardOnly, dbSQLPassThrough)
> If rst.EOF <> True Then
> GetEmployee = True
> strName = Trim(rst!given_name) & " " & Trim(rst!surname)
> End If
> rst.Close
> Set rst = Nothing
> qdf.Close
> Set qdf = Nothing
> Exit Function
> HandleError:
> Call Log(Err.Number & ": " & Err.Description, "modEmployeeManagement:GetEmployee")
> End Function
> Thanks in advance,
> Scott Marcus
> TSS Technologies