Solved

How to convert the .xsl files or .txt file  data into .mdb file through vb programming?

Posted on 2001-06-20
6
201 Views
Last Modified: 2010-05-02
For this ...Iam creating DSN for excel or txt
i have DSN for .mdb

i used the following code
for ex: my txt files
Customer name      Address
Rajani              XXXX
but iam getting the whole line value into rs(0).But i want rs(0) as Rajani and rs(1) as XXXX

how?can u suggest some sample codes?

Rgds,
Rajani

Private Sub chgdata()
 Dim conn As adodb.Connection
     Dim cmd As adodb.Command
    Dim rs As adodb.Recordset
    Set rs = New Recordset
    Set conn = New Connection
     conn.Open "dsn=txtacr"
    mysql = "select * from acrtest.csv"
    rs.Open mysql, conn, adOpenDynamic
    rs.MoveFirst
     Set cmd = New Command
   cmd.ActiveConnection = MDIForm1.dfwConn
   Do While Not rs.EOF
   insql = "insert into cust values('" & rs(0) & "','" & rs(1) & "')"
   MDIForm1.dfwConn.Execute insql

rs.MoveNext
Loop

End Sub
0
Comment
Question by:rajani50
6 Comments
 
LVL 6

Expert Comment

by:simonbennett
ID: 6209797
Hi

Which database are you inserting into?

Simon
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 6209808
<wispering to simonbennett>
MSAccess (read the q-title: .mdb)
</wispering to simonbennett>

0
 
LVL 6

Expert Comment

by:simonbennett
ID: 6209832
<clearsthroat humble=true>

I suppose that means DTS is out of the question then.

Is the file coming from a unix source? If so the row terminators will be different. I would suggest reading the file with the FSO or with OPEN FOR READ, LINE INPUT methods.

HTH

Simon
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 2

Expert Comment

by:damienm
ID: 6210935
If your file is delimited in some way then you it is ok to get a row at a time, then you can format the data into the correct parts.

Then use something like

insql = "insert into cust values('" & trim(left(str,6) &  & "','" & trim(instr(str,6,8)) & "')" etc.
  MDIForm1.dfwConn.Execute insql

0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7139573
Hi rajani50,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will suggest to:

    Save as PAQ -- No Refund.

EXPERTS: Post a comment if you are certain that an expert deserves credit.  Explain why.
==========
DanRollins -- EE database cleanup volunteer
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 7173357
Question placed in PAQ

Computer101
E-E Moderator
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now