Code freezes on opening a recordset. Need help to debug!

Alexandre

Registered User.
Local time
Today, 06:06
Joined
Feb 22, 2001
Messages
794
I wrote a function to automatically fill a table TblAuxGeogr with values in another table TblListGeogr zhen the user selsects a given value in a field. The function freezes at the very begining (Set RsList...) and I can only get out using Crtl+Alt+Supr.

What is wrong in the way I am opening this recordset?

Public Function Referenciar_Localizacao(TblListGeogr As String,
_TblAuxGeogr As String,
_CampoCodGeogr As String,
_CampoRef As String,
_CtlRef As Control) As Boolean

'For an existing contract(ID: CtlRef),
' register in TblAuxGeogr all the
'geographical codes existing in the table
'TblListGeogr

Dim W As Workspace
Dim db As Database
Dim RsList As Recordset
Dim RsCodGeogr As Recordset
Dim QrSQL As String
Dim CodGeogr As String
Dim Tbl As TableDef

On Error GoTo Erro

Referenciar_Localizacao = False
Set W = DBEngine.Workspaces(0)
Set db = CurrentDb
Set Tbl = db.TableDefs(TblListGeogr)

Set RsList = Tbl.OpenRecordset(dbOpenTable,
_dbReadOnly)
QrSQL = "SELECT * FROM [" & TblAuxGeogr & "]
_WHERE ((([" & TblAuxGeogr & "].
_Referencia_Contrato]) = '"
_& CtlRef & "'))"
Set RsCodGeogr = db.OpenRecordset(QrSQL,
_dbOpenDynaset, dbDenyWrite,
_dbPessimistic)
RsList.Index = "PrimaryKey"
 
change the code in this line:

Set RsList = Tbl.OpenRecordset(dbOpenTable,
_dbReadOnly)

to this:

Set RsList = db.OpenRecordset(dbOpenTable,
_dbReadOnly)

replacing Tbl with db

that should work hopefully
 
Use the debugger to single step through your code to determine which line is actually causing the error. That will be a big help to you.
 
Yeaaap! Both of you are very right!
How is it that I didn t find that myself? You must forgive the beginner I am (This is my first DAO code).

Thanks to both
 

Users who are viewing this thread

Back
Top Bottom