Results 1 to 4 of 4

Thread: Creating a text file.

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2003
    Posts
    17

    Creating a text file.

    In my table in the database I have columns FirstNm, MidInt, LName and SurveyNbr. I want to display the rs as a text file. The text file should look something similar to this:

    KPN INC.
    Madison Heights

    No. FirstNm MidInt Lname SurveyNbr


    -
    -

    -
    -
    -
    -
    -


    Reg @2003.

    This is my code so far:
    'Modification Log : Trying to create a connection to MS Access and a txt file

    Option Explicit
    Dim mstrErrorMsg As String
    Dim strSQLTemp As String
    Dim mstrErrorMsg As String



    Private Sub Form_Load()

    On Error GoTo ErrorHandler

    Me.LblStatusMsg.Refresh
    FrmDelete.LblStatusMsg.Caption = "Please Check Begin to Start Processing"
    Me.LblStatusMsg.Refresh
    Me.LblStatusMsg = "GreenMachine Processing Started " & Now
    DoEvents


    Exit Sub

    ErrorHandler:

    ErrorProcess "frmDelete.form_load"

    End Sub

    Private Sub cmdStart_Click()


    Screen.MousePointer = vbHourglass
    Me.LblStatusMsg.Refresh
    Me.LblStatusMsg = "Green Machine Process is Initiated" & Now

    DoEvents
    If Me.ChkDelete.Value = 1 Then
    Call selectprocess
    End If

    End Sub

    Private Sub selectprocess()
    Dim strConnection As String
    Dim rs As ADODB.Recordset
    Dim strSQL As String
    Dim oConnection As New ADODB.Connection 'Define the ADODB Connection

    strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\accessdb.mdb"
    oConnection.CursorLocation = adUseClient
    ' Set the connection string
    oConnection.ConnectionString = strConnection
    ' Set the mode of the connection
    oConnection.Mode = adModeReadWrite
    ' Open the Connection
    oConnection.Open

    strSQL = "Select * From tblGM " 'Get all records from tblExample
    rs.Open strSQL, strConnection, adOpenStatic, adCmdText
    'rs.Close 'Close the recordset never leave it open!
    Set rs = Nothing 'clear the rs variable
    Screen.MousePointer = vbNormal
    End Sub

    Any pointers will be great

  2. #2
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    Hi there Sri2003

    Use the vbcode tags when posting code.

    VB Code:
    1. Option Explicit
    2. Dim mstrErrorMsg As String
    3. Dim strSQLTemp As String
    4. Dim mstrErrorMsg As String
    5.  
    6.  
    7.  
    8. Private Sub Form_Load()
    9.  
    10. On Error GoTo ErrorHandler
    11.      
    12.     Me.LblStatusMsg.Refresh
    13.     FrmDelete.LblStatusMsg.Caption = "Please Check Begin to Start Processing"
    14.     Me.LblStatusMsg.Refresh
    15.     Me.LblStatusMsg = "GreenMachine Processing Started " & Now
    16.     DoEvents
    17.      
    18.  
    19. Exit Sub
    20.  
    21. ErrorHandler:
    22.      
    23.     ErrorProcess "frmDelete.form_load"
    24.  
    25. End Sub
    26.  
    27. Private Sub cmdStart_Click()
    28.  
    29.  
    30.      Screen.MousePointer = vbHourglass
    31.     Me.LblStatusMsg.Refresh
    32.     Me.LblStatusMsg = "Green Machine Process is Initiated" & Now
    33.  
    34.   DoEvents
    35.      If Me.ChkDelete.Value = 1 Then
    36.         Call selectprocess
    37.     End If
    38.    
    39.   End Sub
    40.    
    41. Private Sub selectprocess()
    42. Dim strConnection As String
    43. Dim rs As ADODB.Recordset
    44. Dim strSQL As String
    45. Dim oConnection As New ADODB.Connection 'Define the ADODB Connection
    46.  
    47.  strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\accessdb.mdb"
    48.  oConnection.CursorLocation = adUseClient
    49. ' Set the connection string
    50. oConnection.ConnectionString = strConnection
    51. ' Set the mode of the connection
    52. oConnection.Mode = adModeReadWrite
    53. ' Open the Connection
    54. oConnection.Open
    55.    
    56.      strSQL = "Select * From tblGM " 'Get all records from tblExample
    57.         rs.Open strSQL, strConnection, adOpenStatic, adCmdText
    58.        'rs.Close 'Close the recordset never leave it open!
    59.     Set rs = Nothing 'clear the rs variable
    60. Screen.MousePointer = vbNormal
    61. End Sub

    makes it readable
    -= a peet post =-

  3. #3
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    [vbcode]
    MsgBox "u'r code goes here"
    [/vbcode]

    will look Like this

    VB Code:
    1. MsgBox "u'r code goes here"
    -= a peet post =-

  4. #4
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    I am not 100% sure I understand what you want here, but I think you will have to do something like this:

    VB Code:
    1. Open "C:\test.txt" For Output As #1
    2. Print #1, "KPN INC."
    3. Print #1, "Madison Heights"
    4.  
    5. ' start processing the records
    6. While not rs.eof
    7.    s = rs("Field1") & "" & rs("Field2") & "" & ........
    8.    Print #1, s  
    9. Wend
    10.  
    11. close #1

    something along those lines
    -= a peet post =-

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width