Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 11th, 2003, 01:16 AM
puteri_84 puteri_84 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Singapore
Posts: 3 puteri_84 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to puteri_84
How to write into text file from Access Database

Hello,
Can someone give me example on how to write the data from Access into a text file.
thanks in advance.

Reply With Quote
  #2  
Old October 11th, 2003, 09:09 AM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via MSN to cleverpig
read access data and write it into a text file with some data struct??This is a simple class used to export access databases to text files using DAO, along with an application that uses the class. You can specify which table to export and the number of fields, though as written, you can't specify which fields to include or exclude.
http://www.freevbcode.com/code/expdb.zip

Reply With Quote
  #3  
Old October 11th, 2003, 10:40 AM
BanksySan's Avatar
BanksySan BanksySan is offline
A mule with a spinning wheel.
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Wales
Posts: 113 BanksySan User rank is Corporal (100 - 500 Reputation Level)BanksySan User rank is Corporal (100 - 500 Reputation Level)BanksySan User rank is Corporal (100 - 500 Reputation Level)BanksySan User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 20 h 48 m 39 sec
Reputation Power: 8
MySpace
Cool Simple answer

Use the RecordSet's 'GetString' method.

It is of the form:

recordset.GetString(StringFormat, NumRows, ColumnDelimiter, RowDelimiter, NullExpr)

Follow the link below fo rmore info...

MSDN Library RecordSet.GetString page

Reply With Quote
  #4  
Old October 11th, 2003, 11:13 AM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via MSN to cleverpig
MSDN sample:
Code:
'BeginGetStringVB

    'To integrate this code
    'replace the data source and initial catalog values
    'in the connection string

Public Sub Main()
    On Error GoTo ErrorHandler

     ' connection variables
    Dim Cnxn As ADODB.Connection
    Dim rstAuthors As ADODB.Recordset
    Dim strCnxn As String
    Dim strSQLAuthors As String
    Dim varOutput As Variant
    
     ' specific variables
    Dim strPrompt As String
    Dim strState As String
    
     ' open connection
    Set Cnxn = New ADODB.Connection
    strCnxn = "Provider='sqloledb';Data Source='MySqlServer';" & _
        "Initial Catalog='Pubs';Integrated Security='SSPI';"
    Cnxn.Open strCnxn
    
     ' get user input
    strPrompt = "Enter a state (CA, IN, KS, MD, MI, OR, TN, UT): "
    strState = Trim(InputBox(strPrompt, "GetString Example"))
     
     ' open recordset
    Set rstAuthors = New ADODB.Recordset
    strSQLAuthors = "SELECT au_fname, au_lname, address, city FROM Authors " & _
                "WHERE state = '" & strState & "'"
    rstAuthors.Open strSQLAuthors, Cnxn, adOpenStatic, adLockReadOnly, adCmdText
    
    If Not rstAuthors.EOF Then
    ' Use all defaults: get all rows, TAB as column delimiter,
    ' CARRIAGE RETURN as row delimiter, EMPTY-string as null delimiter
       varOutput = rstAuthors.GetString(adClipString)
        ' print output
       Debug.Print "State = '" & strState & "'"
       Debug.Print "Name             Address             City" & vbCr
       Debug.Print varOutput
    Else
       Debug.Print "No rows found for state = '" & strState & "'" & vbCr
    End If
    
    ' clean up
    rstAuthors.Close
    Cnxn.Close
    Set rstAuthors = Nothing
    Set Cnxn = Nothing
    Exit Sub
    
ErrorHandler:
    ' clean up
    If Not rstAuthors Is Nothing Then
        If rstAuthors.State = adStateOpen Then rstAuthors.Close
    End If
    Set rstAuthors = Nothing
    
    If Not Cnxn Is Nothing Then
        If Cnxn.State = adStateOpen Then Cnxn.Close
    End If
    Set Cnxn = Nothing
    
    If Err <> 0 Then
        MsgBox Err.Source & "-->" & Err.Description, , "Error"
    End If
End Sub
'EndGetStringVB
*edit: added code tags for readability

Last edited by Onslaught : October 11th, 2003 at 01:26 PM.

Reply With Quote
  #5  
Old October 12th, 2003, 05:39 AM
puteri_84 puteri_84 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Singapore
Posts: 3 puteri_84 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to puteri_84
will it be similar if i use a oracle db?

Reply With Quote
  #6  
Old October 12th, 2003, 08:16 AM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via MSN to cleverpig
puteri_84,if u use oracle,U should modify this connect statement in above my program:
strCnxn = "Provider='sqloledb';Data Source='MySqlServer';" & _
"Initial Catalog='Pubs';Integrated Security='SSPI';"
Cnxn.Open strCnxn
==>strCnxn = "Provider=MSDAORA.1;Database=table1; User id=user;Password=***;"
Cnxn.Open strCnxn
...

Reply With Quote
  #7  
Old October 12th, 2003, 09:21 PM
puteri_84 puteri_84 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Singapore
Posts: 3 puteri_84 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to puteri_84
I tried it..but then when i run the form nothing come out. Can you pls tell me step by step instruction of what i should do because i am very new to programming. Thanks a lot..

Reply With Quote
  #8  
Old October 13th, 2003, 12:39 AM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via MSN to cleverpig
OK!

What is VB and what is it used for?
Visual Basic (VB) is an extremely popular and easy to use programming language provided by Microsoft Corporation. VB is mainly used to develop Windows based applications with.

What is DAO, RDO and OLE DB? Which one should one use?
DAO, RDO, ADO and OLE DB are data access methods that all accomplish exactly the same task.
DAO - Data Access Objects (1-tier)
Allow VB applications to talk to a database (the JET Engine) via ODBC. DAO was Microsoft's first object oriented solution for the manipulation of databases using the Jet Database Engine. The JET engine duplicates the functionalities of ODBC, and thus does not add much value. As the JET engine is generic, many of Oracle's features would not be accessible. Microsoft is currently phasing out this method.

RDO - Remote Data Objects (2-tier)
Allow VB applications to talk to a relational database (various Relational DBMSs) via ODBC. RDO is an interface to remote RDBMS via OBDC. One needs the Enterprise Edition of Visual Basic to use RDO. Microsoft is encouraging developers to migrate their RDO programs to ADO and OLE-DB.

ADO - ActiveX Data Objects (1 to n-tier)
Allow VB/Other Web Tools (Browsers) to interface with different kinds of data sources. ADO is a more recent Microsoft Data Access technology designed to replace DAO and RDO. ADO is designed to be simpler to use and more powerful than DAO/RDO. Serves an interface to Microsoft's new OLE-DB technology (thinner than ODBC). Can be used to access all sorts of "non traditional data" (e.g., web pages/documents, etc.).

OLE DB data provider
OLE DB is Microsoft's successor to ODBC that utilizes a set of COM interfaces for accessing and manipulating of data. Oracle implemented OLE DB as part of their "Oracle Provider for OLE DB" client software. It provides interface for both data-consuming applications and database providers. OLE DB is considered a thin middle layer which provides better data access performance.

Summary
RDO and DAO still works in VB for backwards compatibility. However, it is best to convert to ADO or OLE-DB.

How does one connect to Oracle from VB?
Connectivity to Oracle is provided via ODBC or OO4O (Oracle Objects for OLE). For more information about ODBC, read the ODBC FAQ. For information about OO4O, read the OO4O FAQ. Look at this examples:
' DAO Example (Data Access Objects)
Dim wstemp As Workspace
Dim dbtemp As Database
Dim rstemp As Recordset

Set wstemp = DBEngine.Workspaces(0)
Set dbtemp = wstemp.OpenDatabase("", False, False, "ODBC;DSN=Oracle;USR=scott;PWD=tiger")
Set rstemp = dbtemp.OpenRecordset(myquery.Text, dbOpenDynaset, dbSQLPassThrough)
howmany = 0
Combo1.Clear
Do Until rstemp.EOF
msgbox rstemp(0)
rstemp.MoveNext
howmany = howmany + 1
Loop

' DAO Example (Data Access Objects)
Dim contemp As New rdoConnection
Dim rstemp As rdoResultset
Dim envtemp As rdoEnvironment
Set envtemp = rdoEngine.rdoEnvironments(0)
envtemp.CursorDriver = rdUseServer
' or rdUseOdbc, rdUseNone, rdUseIfNeeded, rdUseClientBatch
With contemp
.Connect = "ODBC;DSN=Oracle;USR=scott;PWD=tiger"
.EstablishConnection rdDriverNoPrompt, false, rdoForwardOnly
' or rdoStatic, rdoKeyset, rdoDynamic
End With

Set rstemp = contemp.OpenResultset("select ...") ' Your SQL here
End If

howmany = 0
With rstemp
Do Until .EOF Or howmany > 2000
msgbox .rdoColumns(0)
' Give a message box of the 1st column
.MoveNext
howmany = howmany + 1
Loop

ADO Example
dim conn as ADODB.Connection
dim rs as recordset
Conn.Open "...", "...", "..."
' ^DSN ^User ^Password
Set RS = Conn.Execute( "SELECT * FROM theTable" )
do while not rs.eof
msgbox RS(i).Value
rs.movenext
loop

Set RDODatabase = rdoEnvironments(0).OpenConnection("", rdDriverNoPrompt, True, "") Set RDOResultSet = RDODatabase.OpenResultset(SqlString.Text) TxtNumRows.Text = RDOResultSet.RowCount

Why is there only one record in my recordset?
When you do a recordcount and it return only one record in the recordset, while you know there are more records, you need to move to the last record before doing the count. Look at this example.
Dim rs As Recordset
rs.MoveLast
TxtNumRows.Text = rs.RecordCount

NOTE: Don't forget to do a rs.MoveFirst to get back to the first record again.

All above at the site:http://www.orafaq.org/faqmsvb.htm

Reply With Quote
  #9  
Old October 13th, 2003, 09:05 AM
Fisherman's Avatar
Fisherman Fisherman is offline
Inherits Programmer.Slacker
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Aug 2003
Location: Between my Id and your Ego
Posts: 2,178 Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 9 h 56 m 45 sec
Reputation Power: 111
Send a message via ICQ to Fisherman Send a message via AIM to Fisherman
Wow, Pig... you sure are clever!
__________________
Fisherman

"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." - A.Einstein

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > How to write into text file from Access Database


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT