Link to home
Create AccountLog in
Avatar of DonGarry
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
SOLUTION
Avatar of als315
als315
Flag of Russian Federation image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
ASKER CERTIFIED SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Avatar of DonGarry
DonGarry

ASKER

Thank you so much for your replies...

Both work just fine but I learned a little more from Bill.

Thanks Again!

Don Garry