代碼很簡單的,我這裡的例子是從文本框裡輸入新的數據庫路徑,然後更新鏈接。你參考一下,再改。
Private Sub Command0_Click()
On Error GoTo Err_Command0_Click
Dim cat As ADOX.Catalog
Dim tdf As ADOX.Table
Me.txtDBnewNAME.SetFocus
Set cat = New ADOX.Catalog
Set cat.ActiveConnection = CurrentProject.Connection
Set tdf = cat.Tables("mytable")
tdf.Properties("jet oledb:link datasource") = Me.txtDBnewNAME.Text
Exit_Command0_Click:
Exit Sub
Err_Command0_Click:
MsgBox Err.Description
Resume Exit_Command0_Click
End Sub