
So what’s the problem? Well, suppose our text file is named Fabrikam Employees.txt. This works great: the script will run, and it will report back the name, department, and title of all the Fiscal Specialists.
Microsoft activex data objects ado download for mac code#
Here’s the line of code that specifies the name of the file we want to work with: strFile = “Employees.txt” What we’re doing here is connecting to the folder C:\Scripts\Text files and then querying the file Employees.txt.

ObjConnection, adOpenStatic, adLockOptimistic, adCmdText ObjRecordset.Open “SELECT * FROM ” & strFile & ” WHERE Title = ‘Fiscal Specialist'”, _ “Extended Properties=””text HDR=YES FMT=Delimited””” “Data Source=” & strPathtoTextFile & “ ” & _ StrPathtoTextFile = “C:\Scripts\Text files” Set objRecordSet = CreateObject(“ADODB.Recordset”) Set objConnection = CreateObject(“ADODB.Connection”) If you’d like a list of all the Fiscal Specialists, you can easily retrieve that information using an ADO script similar to this, and without having to read through the text file line-by-line: Const adOpenStatic = 3 Jonathan Haas,Headquarters,Fiscal Specialist But suppose you have a simple text file that looks like this (just pretend there are a thousand or so lines in the file): Name,Department,Title We won’t go into all the details today for more information, take a look at this Scripting Clinic column on MSDN. ADO (ActiveX Data Objects) enables you to use database techniques to read data from a text file. (Actually we stumbled upon the answer to a different question, but as it turned out the same technique that worked for Excel also works for text files.) So at long last, TL, we can give you (or at least your great-great-grandchildren) an answer to the question, “How can I use ADO to open a text file that has spaces in the file name?”īefore we do that we should probably explain the situation to the rest of the world.

Each time we tried something new we failed.Īnd then the other day, while looking up some information on Microsoft Excel, we stumbled upon the answer. Nevertheless, we always had this in the back of our minds, and every now and then we’d try something different, just in case.

So did we give up? As a matter of fact, we did.
