0

I have a function which works fine on my machine if the Microsoft Office 16 Object Library is added in the reference. My question is, how do I use late binding so that I don't have to add the Microsoft Office 16 Object Library from the list of references.

On my Start up form I have:

Private Sub Form_Load()
On Error Resume Next
Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("SELECT CustomerName FROM tblCustomers")
If Err.Number <> 0 Then

MsgBox "Back-end data Not found: " & Err.Number & " " & Err.Description & " Please locate the data 
file!", , "Data file not found"
Call AttachBackEndFile
End If
rs.Close
Set rs = Nothing

DoCmd.Close acForm, "frmStartUp"
DoCmd.OpenForm "frmMain"
End Sub

Function for opening the File Dialog:

Public Function AttachBackEndFile() As Boolean
On Error GoTo 0
Dim oFileDialog As FileDialog
Dim result As VbMsgBoxResult
Set oFileDialog = FileDialog(msoFileDialogFilePicker)
oFileDialog.show

If oFileDialog.SelectedItems.Count = 1 Then
result = RelinkTables(oFileDialog.SelectedItems(1))
If result = vbCancel Then
AttachBackEndFile = False
End If
AttachBackEndFile = True
Else
AttachBackEndFile = False
End Sub

Thank you!

braX
  • 11,506
  • 5
  • 20
  • 33
Fil
  • 469
  • 3
  • 12
  • See [FileDialog with late binding](https://stackoverflow.com/a/9477733/77335) – HansUp Jun 06 '20 at 15:24
  • After reading the two examples. I think I now get it. It looks like the key is to use: `Const msoFileDialogFilePicker As Long = 3` `Dim oFileDialog As Object` `Set oFileDialog = Application.FileDialog(msoFileDialogFilePicker)` Then `With oFileDialog .AllowMultiSelect = Fales .Show .... End With` Thanks @HansUp and @June7. You have made life much bearable. – Fil Jun 06 '20 at 17:48

0 Answers0