Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Function ConnectSQLServer(tableIn As String)
'this module drops all tables and reconnects them to the SQL server defined in the settings table
Dim tdfLinked As TableDef
Dim db As Database
Dim rstSettings As Recordset, rstTables As Recordset
Dim strSQLServer As String
On Error GoTo errHan
Set db = CurrentDb
Set rstSettings = db.OpenRecordset(tableIn, dbOpenDynaset, dbSeeChanges)
If rstSettings.EOF Then
fMsgBox "Critical Error. Settings not found.", vbCritical, "Critical Error!"
Exit Function
End If
If IsNull(rstSettings!SQLServerConnectString) Then
fMsgBox "Critical Error. SQL Server connect string not found.", vbCritical, "Critical Error!"
Exit Function
End If
strSQLServer = rstSettings!SQLServerConnectString
Set rstTables = db.OpenRecordset("tblTableListSQLServer")
With rstTables
Do Until .EOF
If IsNull(!AccessTableName) Then
fMsgBox "Critical Error. Access Table Name for " & !SQLServerTableName & _
" not defined.", vbCritical, "Critical Error!"
Exit Function
End If
Call SysCmd(acSysCmdSetStatus, "Refreshing " & !AccessTableName & "...")
On Error Resume Next
db.TableDefs.Delete !AccessTableName
On Error GoTo errHan
Set tdfLinked = db.CreateTableDef(!AccessTableName)
tdfLinked.Connect = strSQLServer
tdfLinked.SourceTableName = !SQLServerTableName
db.TableDefs.Append tdfLinked
.MoveNext
Loop
End With
Call SysCmd(acSysCmdClearStatus)
Exit Function
errHan:
fMsgBox Err.Number & " " & Err.Description
Call SysCmd(acSysCmdClearStatus)
Exit Function
End Function