travisbrown
Technical User
- Dec 31, 2001
- 1,016
I've moved this here from the MS Office Forum.
I'm trying to set up Excel as a data entry front end for a SQL2K table. I see there are various ways to do this.
The end user will probably want to keep the .xls on their desktop, and the file may move around from user to user. All the examples I've seen have the workbook on a share and you set up a linked server on SQL Server with a declaration of the .xls location and use in combination with a select macro in xls.
What's the best approach for this? Can this be done without setting up a linked server - just a dsn-less macro in the workbook that will insert and select on the db table? I can query the table with the sub below, but how would one update the table.
I'm trying to set up Excel as a data entry front end for a SQL2K table. I see there are various ways to do this.
The end user will probably want to keep the .xls on their desktop, and the file may move around from user to user. All the examples I've seen have the workbook on a share and you set up a linked server on SQL Server with a declaration of the .xls location and use in combination with a select macro in xls.
What's the best approach for this? Can this be done without setting up a linked server - just a dsn-less macro in the workbook that will insert and select on the db table? I can query the table with the sub below, but how would one update the table.
Code:
Sub PSSPROD_MASTER_TMI_TEMPLATE()
Dim qt As QueryTable
Dim servername, database, username, password
servername = "servername"
database = "db"
uid = "abc"
pwd = "def"
' Set up the SQL Statement
sqlstring = "SELECT col1,col2... FROM table"
connstring = "odbc;Driver={SQL Server};Server=" & servername & ";Database=" & database & ";UID=" & uid & ";PWD=" & pwd & ""
With ActiveSheet.QueryTables.Add(Connection:=connstring, Destination:=Range("A1"), Sql:=sqlstring)
.Refresh
End With
End Sub