I have a client that adds several hundred records to the backend everyday. This over time caused the system to slow down as the size of the backend became enormously large. I ended up archive a year's worth of records and after compacting the backend it ran much faster. The issue I now have at hand is the owner would like to be able to access the archived backend to query records. Now I could show him how to change it through the linked table manager but I know a simple button that does the same would go over better. I searched google and came across a person that has code to do the exact task but when I compile it I get a "Argument not optional." error. Here is the code that I added to a module. Can anyone tell me what I am missing from making this work?
Public Function ChangeLinks(strNewPath As String) As Boolean
'************************************************************
' Name: ChangeLinks
' Purpose:
'
' Inputs: strNewPath As String
'
' Returns: Boolean
'
' Author: Arvin Meyer
' Date: September 5, 1998
' Comment: Change the Link to a different back-end database
'
'*************************************************************
On Error GoTo Err_ChangeLinks
Dim db As DAO.Database
Dim i As Integer
Dim strNewPath
Set strNewPath = "C:\test.mdb"
Set db = CurrentDb
For i = 0 To db.TableDefs.Count - 1
If Len(db.TableDefs(i).Connect) > 0 Then
db.TableDefs(i).Connect = ";DATABASE=" & strNewPath
db.TableDefs(i).RefreshLink
End If
Next i
db.TableDefs.Refresh
ChangeLinks = True
Exit_ChangeLinks:
Set db = Nothing
Exit Function
Err_ChangeLinks:
ChangeLinks = False
Select Case Err
Case 0
Case 3044
Resume Next
Case Else
MsgBox Err.Number & ": " & Err.Description
Resume Exit_ChangeLinks
End Select
End Function
Thanks for your help!
Public Function ChangeLinks(strNewPath As String) As Boolean
'************************************************************
' Name: ChangeLinks
' Purpose:
'
' Inputs: strNewPath As String
'
' Returns: Boolean
'
' Author: Arvin Meyer
' Date: September 5, 1998
' Comment: Change the Link to a different back-end database
'
'*************************************************************
On Error GoTo Err_ChangeLinks
Dim db As DAO.Database
Dim i As Integer
Dim strNewPath
Set strNewPath = "C:\test.mdb"
Set db = CurrentDb
For i = 0 To db.TableDefs.Count - 1
If Len(db.TableDefs(i).Connect) > 0 Then
db.TableDefs(i).Connect = ";DATABASE=" & strNewPath
db.TableDefs(i).RefreshLink
End If
Next i
db.TableDefs.Refresh
ChangeLinks = True
Exit_ChangeLinks:
Set db = Nothing
Exit Function
Err_ChangeLinks:
ChangeLinks = False
Select Case Err
Case 0
Case 3044
Resume Next
Case Else
MsgBox Err.Number & ": " & Err.Description
Resume Exit_ChangeLinks
End Select
End Function
Thanks for your help!