Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ODBC to a csv file

Status
Not open for further replies.

mnolting

Programmer
Oct 6, 2008
26
US
I have created a DSN to a csv file and I am able to use it with WinSQL (so I know that the connection works). When I use the connection in Word VBA, I get an error that I can not use ODBC to import , export or link data to my database. When i use this code for any other type of DSN (eg SQL Lite), it works.
How can I use DAO to query records to my csv file (the file belongs to an application, I can not convert it).

Hereis the code:
'-------------------------------------------------------
Public Function ChkAgent(Fname, Lname As String) As Integer
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = OpenDatabase("", True, True, Connect:="DSN=Agents;")
Set rs = dbs.OpenRecordset("select [first name],[last name] from people.csv where ucase([first name]) =ucase('Jessica') and ucase([last name])=ucase('Smith');")
ChkAgent = rst.RecordCount
Set rs = Nothing
Set db = Nothing
End Function
'--------------------------------------------------------
Thanks
Mike
 




Set up a Schema.ini file
[tt]
[resource data.txt]
format=Delimited(|)
col1=Resource Text
col2=ResDesc Text
Col3=CC Text
Col4=ZZ Text
Col5=COE Text
Col6=OTHER Text
Col7=MORE Text
[/tt]
Use a TEXT driver when you connect in MS Word.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Thats what "DSN=Agents" is , its a text DSN created from "Microsoft Text Driver, (*.txt, *.csv)"

Please show me more specifics on how.
Thanks

Mike
 




When you define the location of your source data, first choose the TEXT Files of type. If your Data source is not in the My Data Sources folder, drill to the folder.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
OK,
This is what I did:
1. Created a DSN named "Agents2" using "Text File driver (*.txt, *.csv)" and defined all of the field names.
2. Attemped to open with "Set db = OpenDatabase("", True, True, Connect:="DSN=Agents2;")
3. Got the error when running the macro containing the statement in step 2

Still not sure just what to do next

Mike

 




Why are you using VBA?

Why can't you use Word's MailMerge feature?

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
OK,
Heres the application:
I have a word document that has a lot of information to get a proprietory application started. This application has a list of Agents in a csv file. I can save a lot of typing if I can add the agents information to the file (which I can already do). But to find a agent first name and last name is quite involved and I need to see if the agents already exists before adding one (of course). An sql query to query the "Table" would REALLY be nice and clean. I already have a DSN that works with WinSQL (a stand alone sql utility), so I know that the DSN works. For every job that comes my way, a new word doc is sent to me, I want to use Word's tools to automate my creation of my report in an outside application. I am not useing mail merge.
Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top