Snowflake68
Registered User.
- Local time
- Today, 19:24
- Joined
- May 28, 2014
- Messages
- 464
I have been using code that I obtained from the Microsoft Learn site and have been using this in one of my customer applications for quite some time now (maybe two years). The application opens a form that runs code that uses the function below to relink several SQL tables (it deletes and relinks them). However just lately some of the users are starting to experience errors and it looks to have been caused by a Windows update.
I am not sure how to go about sourcing the issue but when I remove the error trapping it goes to the debug window and stops at the line below.
CurrentDb.TableDefs.Append td
This is probably a red herring and nothing to do with the actual line that it stops on but I am at a loss on where to start with sourcing the issue.
Attached is the error that the end user is getting.
Can anyone advise me where I need to start looking please?
I am not sure how to go about sourcing the issue but when I remove the error trapping it goes to the debug window and stops at the line below.
CurrentDb.TableDefs.Append td
This is probably a red herring and nothing to do with the actual line that it stops on but I am at a loss on where to start with sourcing the issue.
Attached is the error that the end user is getting.
Can anyone advise me where I need to start looking please?
Code:
'//Name : AttachDSNLessTable
'//Purpose : Create a linked table to SQL Server without using a DSN
'//Parameters
'// stLocalTableName: Name of the table that you are creating in the current database
'// stRemoteTableName: Name of the table that you are linking to on the SQL Server database
'// stServer: Name of the SQL Server that you are linking to
'// stDatabase: Name of the SQL Server database that you are linking to
'// stUsername: Name of the SQL Server user who can connect to SQL Server, leave blank to use a Trusted Connection
'// stPassword: SQL Server user password
Function AttachDSNLessTable(stLocalTableName As String, stRemoteTableName As String, stServer As String, stDatabase As String, Optional stUsername As String, Optional stPassword As String)
On Error GoTo AttachDSNLessTable_Err
Dim td As TableDef
Dim stConnect As String
For Each td In CurrentDb.TableDefs
If td.Name = stLocalTableName Then
CurrentDb.TableDefs.Delete stLocalTableName
End If
Next
If Len(stUsername) = 0 Then
'//Use trusted authentication if stUsername is not supplied.
stConnect = "ODBC;DRIVER=SQL Server;SERVER=" & stServer & ";DATABASE=" & stDatabase & ";Trusted_Connection=Yes"
Else
'//WARNING: This will save the username and the password with the linked table information.
stConnect = "ODBC;DRIVER=SQL Server;SERVER=" & stServer & ";DATABASE=" & stDatabase & ";UID=" & stUsername & ";PWD=" & stPassword
End If
Set td = CurrentDb.CreateTableDef(stLocalTableName, dbAttachSavePWD, stRemoteTableName, stConnect)
CurrentDb.TableDefs.Append td
AttachDSNLessTable = True
Exit Function
AttachDSNLessTable_Err:
AttachDSNLessTable = False
MsgBox "AttachDSNLessTable encountered an unexpected error: " & Err.Description
End Function