Private Sub Select_Click()
'Requires reference to Microsoft Office 12.0 Object Library.
Dim fDialog As Office.FileDialog
Dim varFile As Variant
'Set up the File Dialog.
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
With fDialog
'Allow user to make multiple selections in dialog box.
.AllowMultiSelect = True
'Set the title of the dialog box.
.Title = "Choose Database Network Location"
'Clear out the current filters, and add our own.
.Filters.Clear
.Filters.Add "Database", "*.accdb"
.Filters.Add "All Files", "*.*"
'Show the dialog box. If the .Show method returns True, the
'user picked at least one file. If the .Show method returns
'False, the user clicked Cancel.
If .Show = True Then
'Loop through each file selected and add it to the list box.
For Each varFile In .SelectedItems
Me.FileList.AddItem varFile
Next
Else
MsgBox "You clicked Cancel in the file dialog box."
End If
End With
End Sub
Private Sub Update_Click()
Me.FileList.SetFocus
Me.FileList.Selected(0) = True
'If file name has been selected (Default value is 1 so must be longer to show selection)
If Len(Me.FileList.Value) > 1 Then
'Change datapath to selected network drive
Dim tdef As TableDef
Dim Strnew As String
Strnew = ";database=" & Me.FileList
For Each tdef In CurrentDb.TableDefs
If Left(tdef.Connect, Len(";Database=")) = ";database=" Then
If Not InStr(tdef.Connect, "mydb.accdb") Then
Debug.Print tdef.Name; tdef.Connect
tdef.Connect = Strnew
tdef.RefreshLink
End If
End If
Next
End If
'Close form and refresh main form
DoCmd.Close
DoCmd.RunMacro "Refresh"
End Sub