Advertisement

11.12.2007 at 08:30PM PST, ID: 22956361
[x]
Attachment Details

Simple  VBA write text file

Asked by avgplusguy in Access Coding/Macros, VB Controls

Tags: vba, write, file, text

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.FileSystemObject")
    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
[+][-]11.12.2007 at 09:12PM PST, ID: 20269609

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Access Coding/Macros, VB Controls
Tags: vba, write, file, text
Sign Up Now!
Solution Provided By: frankytee
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628