Is Recordset already open ???

  • Thread starter Thread starter George
  • Start date Start date
G

George

Hello to everybody......
Simple question.
Is there a way to determine if a recordset is
already open ???
I want to check if a specific recordset is open before
i use the code-line:
Set myset=mydb.openrecordset...............

Many Thanks in Advance
George
 
the Code MsgBox(myset.Name) will return the name of the
connected table if a connection has been already
established, you could try using this: -

If myset.Name <> "" Then Goto ContinueProramme
Set myset=mydb.openrecordset...............
ContinueProgramme:
[REST OF CODE]

HTH

Tony C.
 
ACK, the dreaded GOTO line:

If rst.Name = "" Then
Set rst=dbs.OpenRecordset("..")
End If


Chris
-----Original Message-----
the Code MsgBox(myset.Name) will return the name of the
connected table if a connection has been already
established, you could try using this: -

If myset.Name <> "" Then Goto ContinueProramme
Set myset=mydb.openrecordset...............
ContinueProgramme:
[REST OF CODE]

HTH

Tony C.
-----Original Message-----
Hello to everybody......
Simple question.
Is there a way to determine if a recordset is
already open ???
I want to check if a specific recordset is open before
i use the code-line:
Set myset=mydb.openrecordset...............

Many Thanks in Advance
George



.
.
 
I want to check if a specific recordset is open before
i use the code-line:
Set myset=mydb.openrecordset...............
This code is fairly self-documenting:

Public Sub TestARecordset()

Dim db As Database
Dim rs As Recordset
Dim strSQL As String

On Error GoTo 0

strSQL = "SELECT Something FROM A WHERE FALSE;"

Set db = CurrentDb()

Debug.Print "Right at the start: ";
If rs Is Nothing Then Debug.Print "rs is nothing";
Debug.Print

Set rs = db.OpenRecordset(strSQL, dbOpenSnapshot, dbForwardOnly)
Debug.Print "After opening the recordset: ";
If rs Is Nothing Then Debug.Print "rs is nothing";
Debug.Print

rs.Close
Debug.Print "After closing it: ";
If rs Is Nothing Then Debug.Print "rs is nothing";
Debug.Print

Set rs = Nothing
Debug.Print "After nothinging it: ";
If rs Is Nothing Then Debug.Print "rs is nothing";
Debug.Print

Set db = Nothing

End Sub



Hope it helps



Tim F
 
Back
Top