自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

access中數(shù)據(jù)表的自動(dòng)重新聯(lián)接

數(shù)據(jù)庫
access數(shù)據(jù)庫的知識(shí)我已經(jīng)為大家介紹了很多,在這里就為大家介紹如何實(shí)現(xiàn)access中數(shù)據(jù)表的自動(dòng)重新聯(lián)接,希望對(duì)大家能夠有所幫助。

導(dǎo)讀:access數(shù)據(jù)庫做應(yīng)用程序,往往做成"數(shù)據(jù)"和"程序"兩個(gè)數(shù)據(jù)庫,"數(shù)據(jù)"數(shù)據(jù)庫中只存放數(shù)據(jù)表,"程序"數(shù)據(jù)庫中存放所有的form,query,report,module等,通過表聯(lián)接"程序"數(shù)據(jù)庫可以訪問所有"數(shù)據(jù)"數(shù)據(jù)庫中的表。 當(dāng)我們的應(yīng)用程序更換存儲(chǔ)位置的時(shí)候往往失去正確的表聯(lián)接,造成運(yùn)行錯(cuò)誤。下面的一段程序可以自動(dòng)找回表聯(lián)接。在我的應(yīng)用中"程序"數(shù)據(jù)庫名字是stockMgr.mdb,"數(shù)據(jù)"數(shù)據(jù)庫名字是stock-Data.mdb
注意: 該程序僅限于"程序"和"數(shù)據(jù)"存放在同一個(gè)目錄而且是對(duì)應(yīng)單個(gè)"數(shù)據(jù)"文件的情況。

Function ReAttachTable()
Dim MyDB As Database, MyTbl As TableDef
Dim cpath As String
Dim datafiles As String, i As Integer

On Error Resume Next
Set MyDB = CurrentDb
cpath = trimFileName(CurrentDb.Name)
datafiles = "stock-data.mdb"
DoCmd.Hourglass True
For i = 0 To MyDB.TableDefs.Count - 1
Set MyTbl = MyDB.TableDefs(i)
If MyTbl.Attributes = DB_ATTACHEDTABLE And Left(MyTbl.Connect, 1) = ";" Then
MyTbl.Connect = ";DATABASE=" & cpath & datafiles
MyTbl.RefreshLink
If Err Then
If vbNo = MsgBox(Err.description & ",繼續(xù)嗎?", vbYesNo) Then Exit For
End If
End If
Next i
DoCmd.Hourglass False
msgbox "Tables relink finish."
End Function

'絕對(duì)路徑中去掉文件名,返回路徑
Function trimFileName(fullname As String) As String
Dim slen As Long, i As Long
slen = Len(fullname)
For i = slen To 1 Step -1
If Mid(fullname, i, 1) = "\" Then
Exit For
End If
Next
trimFileName = Left(fullname, i)
End Function

在程序啟動(dòng)或者按鈕動(dòng)作中調(diào)用即可

掌握了上文中的介紹,就能夠輕松實(shí)現(xiàn)access中數(shù)據(jù)表的自動(dòng)重新聯(lián)接,上文中如果有什么不當(dāng)?shù)牡胤?,還望大家見諒。

【編輯推薦】

  1. Access如何制作復(fù)雜報(bào)表
  2. Access創(chuàng)建一個(gè)簡單MIS管理系統(tǒng)
  3. 使用access數(shù)據(jù)庫時(shí)可能用到的數(shù)據(jù)轉(zhuǎn)換
  4. Access完成累計(jì)余額的計(jì)算
責(zé)任編輯:迎迎 來源: pop222.cn
相關(guān)推薦

2011-03-22 13:11:29

Access數(shù)據(jù)表分頁

2020-05-25 15:50:51

數(shù)字化

2010-11-23 13:51:55

MySQL數(shù)據(jù)表

2009-06-02 10:57:22

ADO.NET多數(shù)據(jù)表操作

2010-05-18 17:17:02

MySQL數(shù)據(jù)表

2011-07-07 10:41:07

php批量刪除

2010-11-22 13:53:46

MySQL數(shù)據(jù)表

2010-06-09 16:55:47

MySQL數(shù)據(jù)表

2010-11-24 13:11:06

MySQL遍歷數(shù)據(jù)表

2010-11-29 13:22:45

sybase數(shù)據(jù)表

2009-09-07 16:13:14

LINQ to SQL

2020-06-02 16:30:58

華為

2009-09-09 11:24:13

Linq使用數(shù)據(jù)表

2009-07-02 09:40:17

JSP導(dǎo)出Oracle

2023-07-26 13:17:04

數(shù)據(jù)表誤刪流程

2010-05-12 18:35:25

MySQL數(shù)據(jù)表

2010-11-24 10:52:57

Mysql字符集

2010-09-01 14:07:33

DB2映射

2010-06-13 17:35:17

MySQL數(shù)據(jù)表

2010-07-22 10:30:36

SQL Server數(shù)
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)