English 中文(简体)
Re-Link to new mdb 然后删除旧数据库(mdb)。
原标题:Re-Link to new mdb then delete old database (mdb)
  • 时间:2011-05-02 17:40:28
  •  标签:
  • ms-access

我有一个程序,最终目的是从一台膝上型计算机更新服务器支持数据库的所有表格。 一旦完成这项工作,我就希望删除当地(过期)mdb,并将删除的文件(mdb)改为服务器。

看来所有工作都做得很好,但我可以删除当地版本,尽管我把手提电脑前线重新连接到服务器后。 我的守则是:

Call CloseALLFormsReports
  Call RelinkTables("K:ProposalsNorthwayDataNorthway Data.accdb")

 ****************************************** 
   backup current c: database
  tBackupfile = "C:ProposalsackupNorthway DATA" & Format(Now(), "yyyymmdd hhmm") & ".accdb"
  Call TransferBEData("C:ProposalsNorthway DATA.accdb", tBackupfile)
   now overwrite c:drive file
    Call TransferBEData("K:ProposalsNorthwayDataNorthway Data.accdb", "C:ProposalsNorthway DATA.accdb")
    Call RelinkTables("C:ProposalsNorthway DATA.accdb")

*************HERE IS THE TransferBEDate function:
Function TransferBEData(ByVal tSource As String, ByVal tDestination As String)

If FileExists(tDestination) Then
  Kill tDestination
End If

FileCopy tSource, tDestination

End Function

************HERE IS MY Relinking Function
Public Sub RelinkTables(strNewPath As String)

Dim dbs As DAO.Database
Dim tdf As TableDef
Dim intCount As Integer
Dim frmCurrentForm As Form
Dim relink As Boolean

DoCmd.Hourglass True
On Error GoTo ErrLinkUpExit
 Me.lblMsg.Visible = True
 Me.cmdOK.Enabled = False

Set dbs = CurrentDb

For intCount = 0 To dbs.TableDefs.Count - 1
Set tdf = dbs.TableDefs(intCount)
If tdf.Connect <> "" Then
 Me.lblMsg.Caption = "Refreshing " & tdf.Name
DoEvents
tdf.Connect = ";DATABASE=" & strNewPath
tdf.RefreshLink
End If   tdf.Connect <> ""
Next intCount

Set dbs = Nothing
Set tdf = Nothing

DoCmd.Hourglass False
 MsgBox ("The file:  " & strNewPath & " was successfully linked.")
 Me.lblMsg.Caption = "All Links were refreshed!"
relink = True
 Me.cmdOK.Enabled = True
Exit Sub

ErrLinkUpExit:
DoCmd.Hourglass False

Select Case Err
Case 3031   Password Protected
 MsgBox "Back End  " & strNewPath & " " & " is password protected"
Case 3011   Table missing
DoCmd.Hourglass False
 MsgBox "Back End does not contain required table  " & _
  tdf.SourceTableName & " "
Case 3024   Back End not found
 MsgBox "Back End Database  " & strNewPath & " " & " " & _
  "Not Found"
Case 3051   Access Denied
 MsgBox "Access to  " & strNewPath & "  Denied " & _
 vbCrLf & _
 " May be Network Security or Read Only Database"
Case 3027   Read Only
 MsgBox "Back End  " & strNewPath & " " & " is Read " & _
 "Only "
Case 3044   Invalid Path
 MsgBox strNewPath & " Is Not a Valid Path"
Case 3265
 MsgBox "Table  " & tdf.Name & " " & _
 " Not Found in   " & strNewPath & " "
Case 3321   Nothing Entered
 MsgBox "No Database Name Entered"
Case Else
 MsgBox "Uncaptured Error " & Str(Err) & " " & _
 Err.Description
End Select

Set tdf = Nothing
relink = False

 ******************Get rid of blank records
DoCmd.SetWarnings False
DoCmd.OpenQuery "Delete_Blank_Material_Records"
DoCmd.SetWarnings True
 ********************************************

End Sub

Function TransferBEData(ByVal tSource As String, ByVal tDestination As String)

If FileExists(tDestination) Then
  Kill tDestination
End If

FileCopy tSource, tDestination

End Function
问题回答

之所以这样做,是因为将表格与另一个来源重新连接,将不会删除24小时档案中的条目(或后来版本的相当于03份)。 你们需要关闭前端数据库,然后重新开放,以便打开当地档案。





相关问题
Handling no results for docmd.applyfilter

I have an Access app where I use search functionality. I have a TextBox and a Search Button on the form, and it does a wildcard search of whatever the user enters in the TextBox, and displays the ...

access query to filter and combine count

i have two access tables tableA num count 1 7 2 8 3 9 4 9 5 13 6 6 tableB num count 0 1 1 14 2 12 3 5 4 5 5 11 6 5 how can i create an access query that ...

How to show File Picker dialog in Access 2007?

I want to show a dialog where the user can pick a file, click OK, and then the path to the file will be saved in the database. I have just one problem, I can t figure out how tho show the dialog ...

MS Access: list macro from VBA

I have to deal with a few macros (not VBA) in an inherited Access application. In order to document them, I would like to print or list the actions in those macros, but I am very dissatisfied by ...

Returning row number on MS Access

I have 4 tables, from which i select data with help of joins in select query...I want a serial no.(row number) per record as they are fetched. first fetched record should be 1, next 2 and so on... In ...

热门标签