|
-
Feb 26th, 2003, 03:36 PM
#1
Thread Starter
Hyperactive Member
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
-
Feb 26th, 2003, 03:45 PM
#2
Frenzied Member
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!!!
-
Feb 26th, 2003, 04:06 PM
#3
Frenzied Member
Here is a quick and dirty way (involves all labels and textboxes).
VB Code:
Option Explicit
Private Sub btnExport_Click()
Dim strText As String
Dim ctl As Control
For Each ctl In Me.Controls
If TypeOf ctl Is Label Then
strText = strText & "lbl;" & ctl.Name & " " & ctl.Caption & vbNewLine
ElseIf TypeOf ctl Is TextBox Then
strText = strText & "txt;" & ctl.Name & " " & ctl.Text & vbNewLine
End If
Next ctl
Open App.Path & "\tempdata.txt" For Output As #1
Print #1, strText
Close #1
End Sub
Private Sub btnImport_Click()
Dim strLine As String, pos%
Dim ctl As Control
Open App.Path & "\tempdata.txt" For Input As #1
Do Until EOF(1)
Line Input #1, strLine
If Not Trim(strLine) = "" Then
pos = InStr(1, strLine, " ")
For Each ctl In Me.Controls
If ctl.Name = Mid(strLine, 5, pos - 1 - 4) Then
If Left(strLine, 3) = "lbl" Then
ctl.Caption = Mid(strLine, pos + 1)
ElseIf Left(strLine, 3) = "txt" Then
ctl.Text = Mid(strLine, pos + 1)
End If
End If
Next ctl
End If
Loop
Close #1
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|