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"
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"