Excellent. Thank you for your prompt working response
Main Topics
Browse All TopicsMS Access 2003 writing MS Access 2000 database.
I just started trying to write VBA and put two previous code pieces together and of course it does not work. I want to pass a three letter code that will be used to open a table where the entity = abbreviation.
I want to write out a text file that is named that abbreviation. Table APR_DRG,
Here is code that needs some help
Sub ExportTstar()
Dim cnn As New DAO.Connection
Dim db As DAO.Database
Dim rs As New DAO.Recordset
Dim fso As Object
Dim ts As Object
Dim Abbrev As String
Abbrev = InputBox("Please enter Enity")
If Abbrev = "" Then
MsgBox "Abort", vbCritical
Exit Sub
End If
' DoCmd.OpenQuery "qBAS", acNormal, acEdit
Set fso = CreateObject("Scripting.Fi
Set ts = fso.CreateTextFile("c:\" & Abbrev & ".ctf", True)
Set rs = db.OpenRecordset("APR_DRG"
Set cnn = CurrentProject.Connection
With rs
Set .ActiveConnection = cnn
' .Open "SELECT * FROM [APR_DRG] WHERE [Entity]= Abbrev "
.MoveFirst
Do While Not .EOF
ts.WriteLine "CHA," & ![ACCOUNT_NO] & ", " & ![Discharge_Date]
ts.WriteLine ".APRDRG :" & ![APR20_DRG]
ts.WriteLine ".APR_MDC" & ![APR_MDC]
ts.WriteLine ".APRSUB :" & ![APR20_SOI]
ts.WriteLine ".APRRMOR :" & ![APR20_ROM]
ts.WriteLine "APR_CMI :" & ![APR20_CMI]
ts.WriteLine "3MDRG_V24 :" & ![CMS24_DRG]
ts.WriteLine "3MDRG_V25 :" & ![CMS25_DRG]
.MoveNext
Loop
End With
Set rs = Nothing
Set cnn = Nothing
ts.Close
Set ts = Nothing
Set fso = Nothing
MsgBox "Done"
End Sub
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: frankyteePosted on 2007-11-12 at 21:12:24ID: 20269609
you are mixing DAO with ADO, just stick with DAO in an Access environment, modified code with corrections below. backup your db first!!
---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------
---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------
leSystemOb ject")
---------- ---------- ---------- ---------- ) ---------- ---------- ---------- ----------
---------- ---------- ---------- ----------
---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------
Sub ExportTstar()
'-------------------------
'FT: comment out below
'Dim cnn As New DAO.Connection
'-------------------------
Dim db As DAO.Database
Dim rs As DAO.Recordset 'remove "NEW"
Dim fso As Object
Dim ts As Object
Dim Abbrev As String
Abbrev = InputBox("Please enter Enity")
If Abbrev = "" Then
MsgBox "Abort", vbCritical
Exit Sub
End If
'-------------------------
'FT: create db object
Set db = CurrentDb
'-------------------------
Set fso = CreateObject("Scripting.Fi
Set ts = fso.CreateTextFile("c:\" & Abbrev & ".ctf", True)
'-------------------------
'FT: comment out
'Set rs = db.OpenRecordset("APR_DRG"
'Set cnn = CurrentProject.Connection
'-------------------------
'FT: is entity a numeric field? if so then (commented out below)
'Set rs = db.OpenRecordset("SELECT * FROM [APR_DRG] WHERE [Entity]= " & Abbrev)
'FT: is entity a text field? if so then
Set rs = db.OpenRecordset("SELECT * FROM [APR_DRG] WHERE [Entity]= '" & Abbrev & "'")
If rs.RecordCount = 0 Then
MsgBox "record does not exist!!", vbExclamation
Set db = Nothing
Exit Sub
End If
'-------------------------
With rs
'-------------------------
'FT: comment out
'Set .ActiveConnection = cnn
'-------------------------
.MoveFirst
Do While Not .EOF
ts.WriteLine "CHA," & ![ACCOUNT_NO] & ", " & ![Discharge_Date]
ts.WriteLine ".APRDRG :" & ![APR20_DRG]
ts.WriteLine ".APR_MDC" & ![APR_MDC]
ts.WriteLine ".APRSUB :" & ![APR20_SOI]
ts.WriteLine ".APRRMOR :" & ![APR20_ROM]
ts.WriteLine "APR_CMI :" & ![APR20_CMI]
ts.WriteLine "3MDRG_V24 :" & ![CMS24_DRG]
ts.WriteLine "3MDRG_V25 :" & ![CMS25_DRG]
.MoveNext
Loop
End With
Set rs = Nothing
'Set cnn = Nothing
ts.Close
Set ts = Nothing
Set fso = Nothing
MsgBox "Done"
End Sub