MS 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
leSystemOb
ject")
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
Start Free Trial