Snowflake68
Registered User.
- Local time
- Today, 05:20
- Joined
- May 28, 2014
- Messages
- 464
I have a function that is called when my application is launched, and it relinks my SQL tables. Which was working perfectly well until I move some local Access tables into SQL and then had to renamed them in order for the application to continue working.
For example I had a local backend Acccess table called 'tbl_Conv_ColumnQty' which is now in SQL but when I linked the table into my application is is prefixed with dbo_ and so the table name is dbo_tbl_Conv_ColumnQty. I have renamed the table to remove the dbo_ so that my application continues to work.
However the function no longer works because I have renamed the table and i now get a message saying that it cannot find the linked table 'tbl_Conv_ColumnQty'
I did not write this function myself so I dont know if it can be amended to add the dbo_ part so that it looks for the correct table name. Can anyone help with amending the function please?
The table called 'tblConnections' contains this as the active ConnectionString.
ODBC;DSN=SysproCompanyT;Description=SysproCompanyT;Trusted_Connection=Yes
For example I had a local backend Acccess table called 'tbl_Conv_ColumnQty' which is now in SQL but when I linked the table into my application is is prefixed with dbo_ and so the table name is dbo_tbl_Conv_ColumnQty. I have renamed the table to remove the dbo_ so that my application continues to work.
However the function no longer works because I have renamed the table and i now get a message saying that it cannot find the linked table 'tbl_Conv_ColumnQty'
I did not write this function myself so I dont know if it can be amended to add the dbo_ part so that it looks for the correct table name. Can anyone help with amending the function please?
Function RelinkSQLTablesAndViews()
'Re-links any tables and views using the active connections strings in the tblConnections table
Dim db As Database
Set db = CurrentDb
Dim tdef As TableDef
Dim indexSQL As String
Dim fld As Field
Dim constr As Variant
Dim HasIndex As Boolean
constr = DLookup("ConnectionString", "tblConnections", "Active = True")
For Each tdef In db.TableDefs
If InStr(tdef.Connect, "ODBC") Then
HasIndex = False
If tdef.Indexes.Count = 1 Then
' only interested in objects with 1 index
indexSQL = "CREATE INDEX " & tdef.Indexes(0).Name & " ON [" & tdef.Name & "](" & tdef.Indexes(0).Fields & ")"
' convert field list from (+fld1;+fld2) to (fld1,fld2)
indexSQL = Replace(indexSQL, "+", "")
indexSQL = Replace(indexSQL, ";", ",")
HasIndex = True
End If
tdef.Connect = constr
tdef.RefreshLink
If HasIndex And tdef.Indexes.Count = 0 Then
' if index now removed then re-create it
CurrentDb.Execute indexSQL
End If
End If
Next
Call ShowSplashScreen("frmSplash", 3)
Exit Function
Continue:
DoCmd.Close acForm, "frmRefreshTables"
DoCmd.OpenForm "frmSplash"
DoCmd.Close acForm, "frmMain"
End Function
The table called 'tblConnections' contains this as the active ConnectionString.
ODBC;DSN=SysproCompanyT;Description=SysproCompanyT;Trusted_Connection=Yes