Confirm connection to table exists

kwvh
3StarLounger
Posts: 308
Joined: 24 Feb 2010, 13:41

Confirm connection to table exists

Post by kwvh »

This has probably been asked and answered, but I can't find exactly what I am seeking. I would like to check and confirm that the connection to a table in a database on a server exists and check to see if the connection exists to a table on a Microsoft SQL Server.

I have an Access database that uses backend tables in both Access and SQL Server. I need to check for the tables when user first loads the start up form. Is there an easy way to accomplish this in VBA?

Thanks in advance for your assistance.

Ken

JohnH
3StarLounger
Posts: 287
Joined: 09 Mar 2010, 23:16
Location: Canberra Australia

Re: Confirm connection to table exists

Post by JohnH »

You can just try to open a recordset based on a table and see if there is an error.

Code: Select all

Function CheckLinks(strTableName as String) As Boolean
On Error Resume Next
Dim dbs As DAO.Database
Dim rst As DAO.Recordset

Set db = CurrentDb()
Set rst = db.OpenRecordset(strTableName)

If Err = 0 Then
CheckLinks = True
Else
CheckLinks = False
End If
End Function
This function is in lots of places, but I copied it from here this time.
Regards

John