重新定位链接表二步走[Access防范]
本文“重新定位链接表二步走[Access防范]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:
固然Accxp网上有很多关于定位链接表的贴子,但还是有很多的朋友询问这方面的问题.应letter网友的提议,结合Alex总版主的重新定位链接表文件源码,现将这方面的具体操作介绍以下:
假定前台数据库文件名为frontBase.mdb
后台数据库文件名为backData.mdb
frontBase当中有链接表tbl1, tbl2, tbl3, …,链接到backData.mdb中
首先我们要在前台数据库文件的启动窗体加载事件中判断链接能否精确
办法是翻开肆意一个链接表,假定为tbl1,代码以下:
Public Function CheckLinks() As Boolean
' 查抄到后台数据库的链接;假如链接存在且精确的话,返回 True .
Dim dbs As Database, rst As DAO.Recordset
Set dbs = CurrentDb()
' 翻开链接表查看表链接信息能否精确.
On Error Resume Next
Set rst = dbs.OpenRecordset("tbl1")
rst.Close
' 假如没有错误,返回 True .
If Err = 0 Then
CheckLinks = True
Else
CheckLinks = False
End If
End Function
启动窗体的加载事件:
Private Sub FORM_Load()
If CheckLinks = False then
Docmd.OpenFORM "frmConnect"
End If
End Sub
frmConnect 衔接窗体以下图
接下来的事情就是若何革新链接表了.
上面的窗体右边的按钮是用用来调用API翻开文件对话框,具体代码以下:
Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Boolean
Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Private Sub FileOpen_Click()
Dim ofn As OPENFILENAME
Dim rtn As String
ofn.lStructSize = Len(ofn)
ofn.hwndOwner = Me.hwnd
ofn.lpstrFilter = "数据库文件 (*.mdb)" & VBNullChar & "*.mdb"
ofn.lpstrFile = Space(254)
ofn.nMaxFile = 255
ofn.lpstrFileTitle = Space(254)
ofn.nMaxFileTitle = 255
ofn.lpstrInitialDir = CurrentProject.Path
ofn.lpstrTitle = "后台数据文件为"
ofn.flags = 6148
rtn = GetOpenFileName(ofn)
FileName.SetFocus
If rtn = True Then
FileName.Text = ofn.lpstrFile
FileName.Text = FileName.Text
OK.Enabled = True
Else
FileName.Text = ""
End If
End Sub
衔接按钮革新链接表 ,代码以下:
Private Sub OK_Click()
Dim tabDef As TableDef
For Each tabDef In CurrentDb.TableDefs
If Len(tabDef.Connect) > 0 Then
tabDef.Connect = ";DATABASE=" & Me.FileName.Text & ";PWD=" + 后台数据库密码
tabDef.RefreshLink
End If
Next
MsgBox "衔接成功!"
DoCmd.Close acFORM, Me.Name
End Sub
其实很简单只有两步,判断链接能否精确和革新链接表.
以上是“重新定位链接表二步走[Access防范]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:
本文地址: | 与您的QQ/BBS好友分享! |
- ·上一篇文章:避免Access 2000密码被破译的办法
- ·下一篇文章:加解密文本的函数
- ·中查找“重新定位链接表二步走”更多相关内容
- ·中查找“重新定位链接表二步走”更多相关内容