Results 1 to 3 of 3

Thread: Export Form Data to File

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2001
    Posts
    302

    Export Form Data to File

    Is there an easy way of exporting all data (from fields in a form) to a text file? And to load it back into the form at a later time...

    I know that I can use an MDB, but I would prefer a text file.... I have many fileds (text, true/false, option, ...)


    thank you

  2. #2
    Frenzied Member mxnmx's Avatar
    Join Date
    Dec 2001
    Location
    I'm back...now!!!
    Posts
    1,396
    If you search the forums or planet source code you might get an already made app to do this but it wont take much time if you diy. Just use the Print# to write dump everything into a Textfile, read about Print# command in MSDN and have a look at the examples and then to load it back into the form, read about Input# statement in MSDN...Enjoy!!!
    Can't Remember Birthdays or Important Dates- Never Miss any Important Date(s)

  3. #3
    Frenzied Member McGenius's Avatar
    Join Date
    Jan 2003
    Posts
    1,199
    Here is a quick and dirty way (involves all labels and textboxes).
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub btnExport_Click()
    4. Dim strText As String
    5. Dim ctl As Control
    6.  
    7.     For Each ctl In Me.Controls
    8.         If TypeOf ctl Is Label Then
    9.             strText = strText & "lbl;" & ctl.Name & " " & ctl.Caption & vbNewLine
    10.         ElseIf TypeOf ctl Is TextBox Then
    11.             strText = strText & "txt;" & ctl.Name & " " & ctl.Text & vbNewLine
    12.         End If
    13.     Next ctl
    14.     Open App.Path & "\tempdata.txt" For Output As #1
    15.         Print #1, strText
    16.     Close #1
    17.  
    18. End Sub
    19.  
    20. Private Sub btnImport_Click()
    21. Dim strLine As String, pos%
    22. Dim ctl As Control
    23.  
    24.     Open App.Path & "\tempdata.txt" For Input As #1
    25.         Do Until EOF(1)
    26.             Line Input #1, strLine
    27.             If Not Trim(strLine) = "" Then
    28.                 pos = InStr(1, strLine, " ")
    29.                 For Each ctl In Me.Controls
    30.                     If ctl.Name = Mid(strLine, 5, pos - 1 - 4) Then
    31.                         If Left(strLine, 3) = "lbl" Then
    32.                             ctl.Caption = Mid(strLine, pos + 1)
    33.                         ElseIf Left(strLine, 3) = "txt" Then
    34.                             ctl.Text = Mid(strLine, pos + 1)
    35.                         End If
    36.                     End If
    37.                 Next ctl
    38.             End If
    39.         Loop
    40.     Close #1
    41.  
    42. End Sub
    McGenius

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