|
-
May 6th, 2003, 12:13 AM
#1
Thread Starter
Junior Member
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
-
May 6th, 2003, 02:01 AM
#2
-= B u g S l a y e r =-
Hi there Sri2003 
Use the vbcode tags when posting code.
VB Code:
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
makes it readable
-
May 6th, 2003, 02:03 AM
#3
-= B u g S l a y e r =-
[vbcode]
MsgBox "u'r code goes here"
[/vbcode]
will look Like this
VB Code:
MsgBox "u'r code goes here"
-
May 6th, 2003, 02:09 AM
#4
-= B u g S l a y e r =-
I am not 100% sure I understand what you want here, but I think you will have to do something like this:
VB Code:
Open "C:\test.txt" For Output As #1
Print #1, "KPN INC."
Print #1, "Madison Heights"
' start processing the records
While not rs.eof
s = rs("Field1") & "" & rs("Field2") & "" & ........
Print #1, s
Wend
close #1
something along those lines
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
|