Find if Recordset exist

Hello experts!

I need to find out if a recordset exists in my database.
I have tried open the database and then a recordset with the given name, but since/if it do not exist then I ofcource get an error. Is there a nice  way to handle this? I want to see if it exist. Maybe a simple IF..then.. way??

Thank you
/Jens* - sorry but I only have these 10points...but guess it is an easy one.
Jens979Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

alokanantCommented:
Hi Jens,

You can use the foll. code to display all the tables in the database. This includes the system tables. The name of system tables begins with MSys... In case the table you r referring to in the select clause does not exist in the database, it shall give an error message. You can replace the MsgBox statement with a suitable if clause.

   Dim db As Database
   Dim i As Integer
   Set db = Workspaces(0).OpenDatabase("c:\winnt\profiles\90127\alok\vb5\db1.mdb")
   For i = 1 To db.TableDefs.Count
    MsgBox db.TableDefs(i).Name
   Next i

hth
alok
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jens979Author Commented:
It is not that I want to count the tables, I want to look for a specific.
Named fx 'brian'.

/Jens*
0
richtsteigCommented:
What about this little function:

Function DBTblExists(thisdb As Database, tblName As String) As Boolean

Dim Dummy As String

On Error GoTo DbTblExistsErr

Dummy = thisdb.TableDefs(tblName).Name
DBTblExists = True
Exit Function

DbTblExistsErr:
DBTblExists = False
End Function

You could use it inside your programm eg like

Dim db as database
db = openDatabas(....)

If dbTblExists(db,"brian") Then
   ...
Else
   ...
End If
0
alokanantCommented:
Hi Jeff,

As I have already mentioned u can replace the msgbox function by a statement like if db.TableDefs(i).Name
   = "brian" then 'do ....

richsteig has suggested another method.

hth
alok
0
Jens979Author Commented:
Ok thanks guys!
:)

/Jens*
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.