I'm now working in Windows 7 and Word 2013. This is an absolutely clean machine set up and used only for this kind of work.
I've written an Initialize procedure in a userform to go and search an Excel database file. The end result when I try to run it it says that it cannot find the .xls file.
It works fine until this line and then tells me that it is an invalid argument.
Set db = OpenDatabase(inifileloc2, False, False, "Excel 8.0")
This is the code for the procedure I'm referring to:
Private Sub UserForm_Initialize()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim iNoOfRecords As Integer
'Won't let the default button become active if the "Default is selected as the default.
If cboOfficeLocation.Value = "My Default" Then
cmdDefaultOffice.Enabled = False
cmdOK.Enabled = True
End If
VarPathLocal = Options.DefaultFilePath(wdUserTemplatesPath)
FullPath = VarPathLocal + "\" + "My Office Details.xls"
inifileloc2 = FullPath
' Open the database
cmdDefaultOffice.Enabled = False
Set db = OpenDatabase(inifileloc2, False, False, "Excel 8.0")
' Retrieve the recordset
Set rs = db.OpenRecordset("SELECT * FROM `MyOfficeRange`")
' Determine the number of retrieved records
With rs
.MoveLast
iNoOfRecords = .RecordCount
.MoveFirst
End With
...and so on through the initialisation procedure.
The References set are as follows:
Visual Basic for Applications
Microsoft Word 16.0 Object Library
OLE Automation
Microsoft Office 16 Object Library
Microsoft Forms 2.0 Object Library
Microsoft DAO 3.6 Object Library
For the life of me I cannot see where the incorrect logic is being entered!
Can anyone suggest a method that might work, please?