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
Confirm connection to table exists
-
- 3StarLounger
- Posts: 287
- Joined: 09 Mar 2010, 23:16
- Location: Canberra Australia
Re: Confirm connection to table exists
You can just try to open a recordset based on a table and see if there is an error.
This function is in lots of places, but I copied it from here this time.
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
Regards
John
John