方法1:createTableDEFメソッドを使用します
createTableDEFメソッドは、リンクテーブルを作成します。この方法を使用するには、新しいモジュールを作成し、新しいモジュールに次のAttachDsnlessTable関数を追加します。
コードコピーは次のとおりです。
'//名前:attachdsnlessTable
'//目的:createalinkedtabletosqlserverwithoutusingadsn
'//パラメーター
'// stlocaltablename:inthecurrentdatabaseのatablethatyourecreatingの名前
'// stremoteTableName:SQL Serverデータベースをリンクしていることができるという名前の名前
'// stserver:you arelinkingto to sqlサーバーの名前
'// stdatabase:リンクしているSQL Serverデータベースの名前
'// Stusname:SQL Serverユーザーの名前whocan connect in sql server、revhapleblank touseatedconnection
'// stpassword:sqlserveruserpassword
functionAttachdsnlessTable(stlocaltablenameasstring、stremoteTablenameasstring、stserverastring、stdatabaseasstring、optionalstusernameasstring、optionalstpasswordasstring)
onerrorgotoattachdsnlesstable_err
dimtdastableef
dimstconnectasstring
foreachtdincurrentdb.tabledefs
iftd.name = stlocaltablenamethen
currentDB.TableDEFS.DELETESTLOCALTABLENAME
endif
次
iflen(stusername)= 0then
'// usettrusted authenticationifstusernameisnotsupplied。
stconnect = "odbc; driver = sqlserver; server ="&stserver& "; database ="&stdatabase& "; trusted_connection = yes"
それ以外
'//警告:これにより、TheLinkedTable情報を使用してTheUsernameとThePasswordが表示されます。