DonGarry
asked on
Access to SQL Server Syntax
Hello Experts,
I have an MS Access Frontend and am in the process of linking tables to a MS SQL backend.
I'm using the following code which works fine...
Public Sub LinkTables()
Dim strSQLServer As String
strSQLServer = "NameOfSQLServer"
DoCmd.TransferDatabase acLink, "ODBC Database", "ODBC;Driver={SQL Server};Server=" & strSQLServer & ";Database=DMS; Uid=sa;Pwd=mypswd", acTable, "dbo.MyTable1", "MyTable"
'What I would like to do to the above DoCmd is change "dbo.MyTable1" and "MyTable"
'to string variables as shown below:
Dim strSQLTableName as string
Dim strAccessTableName as string
strSQLTableName = "dbo.MyTable1"
strAccessTableName = "MyTable1"
'I've tried the following which errors out...
DoCmd.TransferDatabase acLink, "ODBC Database", "ODBC;Driver={SQL Server};Server=" & strSQLServer & ";Database=DMS; Uid=sa;Pwd=mypswd", acTable, " & strSQLTableName & ", " & MyTable1 & "
'Can someone provide me with the correct syntax??
End Sub
I have an MS Access Frontend and am in the process of linking tables to a MS SQL backend.
I'm using the following code which works fine...
Public Sub LinkTables()
Dim strSQLServer As String
strSQLServer = "NameOfSQLServer"
DoCmd.TransferDatabase acLink, "ODBC Database", "ODBC;Driver={SQL Server};Server=" & strSQLServer & ";Database=DMS; Uid=sa;Pwd=mypswd", acTable, "dbo.MyTable1", "MyTable"
'What I would like to do to the above DoCmd is change "dbo.MyTable1" and "MyTable"
'to string variables as shown below:
Dim strSQLTableName as string
Dim strAccessTableName as string
strSQLTableName = "dbo.MyTable1"
strAccessTableName = "MyTable1"
'I've tried the following which errors out...
DoCmd.TransferDatabase acLink, "ODBC Database", "ODBC;Driver={SQL Server};Server=" & strSQLServer & ";Database=DMS; Uid=sa;Pwd=mypswd", acTable, " & strSQLTableName & ", " & MyTable1 & "
'Can someone provide me with the correct syntax??
End Sub
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Both work just fine but I learned a little more from Bill.
Thanks Again!
Don Garry