MS Office Access 2003
MS Windows XP Pro, SP2, etc.
No errors on this one at all, but doesn't do anything that I can see..
I am attempting to create a linked table to a SQL SERVER table via VBA. Here is my code:
The highlighed code is the line that is not working. Everything else works exactly correct, no problems.
Thanks for any pointers/advice.
MS Windows XP Pro, SP2, etc.
No errors on this one at all, but doesn't do anything that I can see..
I am attempting to create a linked table to a SQL SERVER table via VBA. Here is my code:
Code:
Private Sub Form_Load()
On Error GoTo ErrHandle
Dim strSQL
Dim cn As New ADODB.Connection
Dim connString As String
Dim strUserID As String
Dim recordsaffected As Long
Dim tdf As TableDef
connString = "Provider=MSDASQL.1;" & _
"Persist Security Info=False;" & _
"Data Source=MyDatabaseName"
cn.ConnectionString = connString
cn.Open connString
cn.CommandTimeout = 300
strSQL = "SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED " & _
"SET NOCOUNT OFF " & _
"SELECT dbo.sysobjects.name AS 'TableName', dbo.sysobjects.id AS 'sysID', dbo.syscolumns.name AS 'ColumnName', sysusers.name AS 'Owner', sysusers.uid As 'UserID' " & _
"INTO Sandbox.[MYDOMAIN\" & Environ("UserName") & "].SandboxTables " & _
"FROM dbo.sysobjects INNER JOIN " & _
" dbo.syscolumns ON dbo.sysobjects.id = dbo.syscolumns.id INNER JOIN " & _
" dbo.sysusers ON dbo.sysobjects.uid = sysusers.uid " & _
"ORDER BY 5, 4, 1"
cn.Execute strSQL, recordsaffected
[HIGHLIGHT] Set tdf = CurrentDb.CreateTableDef("Sandbox", , "Sandbox.[SHERMAN\" & Environ("UserName") & "].SandboxTables", connString)[/HIGHLIGHT]
Exit Sub
ErrHandle:
MsgBox "An Error Has Occurred!" & _
Chr(13) & Chr(13) & "Error Number" & Chr(9) & "Error Description" & Chr(13) & _
Err.Number & Chr(9) & Chr(9) & Err.Description, vbCritical, "Error!"
End Sub
The highlighed code is the line that is not working. Everything else works exactly correct, no problems.
Thanks for any pointers/advice.