- ©«¤l
- 37
- ¥DÃD
- 29
- ºëµØ
- 0
- ¿n¤À
- 70
- ÂI¦W
- 6
- §@·~¨t²Î
- win10
- ³nÅ骩¥»
- excel 2010
- ¾\ŪÅv
- 20
- µù¥U®É¶¡
- 2025-1-7
- ³Ì«áµn¿ý
- 2025-1-23
|
¥H«e¦bºô¤W¬Ý¨ìªº~~
Function AttachDSNLessTableSQLServer(stLocalTableName As String, _
stRemoteTableName As String, _
stServer As String, _
stDatabase As String, _
Optional stUsername As String, _
Optional stPassword As String, _
Optional strKey As String, _
Optional strDescription As String = "")
' stLocalTableName ¥»¦a¸ê®Æªí¦WºÙ
' stRemoteTableName ¦øªA¾¹¸ê®Æªí¦WºÙ
' stServer ¦øªA¾¹¦WºÙ©ÎIP
' stDatabase ¸ê®Æ®w¦WºÙ
' stUsername ¨Ï¥ÎªÌ¦WºÙ
' stPassword ¨Ï¥ÎªÌ±K½X
' strKey ¯Á¤Þ®M¥ÎÄæ¦ì
' strDescription ¸ê®Æªí´yz
On Error GoTo AttachDSNLessTableSQLServer_Err
Dim td As TableDef
Dim stConnect As String
CurrentDb.TableDefs.Delete stLocalTableName
If Len(stUsername) = 0 Then
'//Use trusted authentication if stUsername is not supplied.
stConnect = "ODBC;DRIVER=SQL Server;SERVER=" & stServer & ";DATABASE=" & stDatabase & ";Trusted_Connection=Yes"
Else
'//WARNING: This will save the username and the password with the linked table information.
stConnect = "ODBC;DRIVER=SQL Server;SERVER={" & stServer & "};DATABASE=" & stDatabase & ";UID=" & stUsername & ";PWD=" & stPassword
End If
Set td = CurrentDb.CreateTableDef(stLocalTableName, dbAttachSavePWD, stRemoteTableName, stConnect)
CurrentDb.TableDefs.Append td
'«Ø¥ß¯Á¤Þ
If Len(strKey) > 0 Then
DoCmd.RunSQL "CREATE UNIQUE INDEX UniqueIndex ON [" & stLocalTableName & "] (" & strKey & ")"
End If
'«Ø¥ß´yz
If strDescription <> "" Then
Set prp = CurrentDb.TableDefs(stLocalTableName).CreateProperty("Description", dbText, strDescription)
CurrentDb.TableDefs(stLocalTableName).Properties.Append prp
End If
AttachDSNLessTableSQLServer = True
Exit Function
AttachDSNLessTableSQLServer_Err:
If err.Number = 3265 Then
'§R°£³sµ²¸ê®Æªí®É¡A¸ê®Æªí¤£¦s¦b
Resume Next
Else
AttachDSNLessTableSQLServer = False
MsgBox "AttachDSNLessTableSQLServer encountered an unexpected error: " & err.Description
End If
End Function |
|