Solved

dBase to Access

Posted on 1997-05-21
3
387 Views
Last Modified: 2013-11-24
I need to read any dBase 4 file and convert it automatically to an Access file with the same field structure.

However, i cannot read the dbase file and find out the fieldproperties.

Wh can help me??

Thanks
0
Comment
Question by:admannien
3 Comments
 

Expert Comment

by:mikekr
ID: 1426467
I think the easiest would be to import your existing dBase files into MS Access. In MS Access ver 7, click on the Tables tab, click the New button, and select Import Table from the list. Click OK and a window will open asking for details of the import. From Combo Box tiltled Files of type, you can select dBase III, dBase IV, or dBase V.

If you have to code it, try the following... I haven't tried this myself, but I guess it would work. Attach the dBase file to an existing Access (MDB) at run-time, and then use the normal collections to return information about the attached dBase table.
0
 

Author Comment

by:admannien
ID: 1426468
I really have to code it in visual basic without useing access.

It has to be a kind of file converter.
0
 
LVL 3

Accepted Solution

by:
ChrisLewis earned 50 total points
ID: 1426469
Not an easy question, but here you go:

You will have to change your table names

Private Sub Command1_Click()
  Dim wrkJet As Workspace
  Dim dbConvert As Database
  Dim tdef As TableDef
  Dim tdef2 As TableDef
  Dim iCount As Integer
  Dim iCount2 As Integer
  Dim fldField1 As Field
  Dim fldField2 As Field
  Dim prpLoop As Property

  If Len(Dir$("C:\CONVERT.MDB")) <> 0 Then
    Kill "C:\CONVERT.MDB"
  End If
 
  ' Create Microsoft Jet Workspace object.
  Set wrkJet = Workspaces(0)
  Set dbConvert = wrkJet.CreateDatabase("C:\CONVERT.MDB", dbLangGeneral)
  'Attach dbase file
  Set tdef = dbConvert.CreateTableDef("DBaseFile")
  tdef.Connect = "dBase III;DATABASE=C:\"
  tdef.SourceTableName = "County"
  dbConvert.TableDefs.Append tdef
 
  'Create new table w/ exact fields
  Set tdef2 = dbConvert.CreateTableDef("NewTable")
  For iCount = 0 To tdef.Fields.Count - 1
    Set fldField1 = tdef.Fields(iCount)
    Set fldField2 = tdef2.CreateField()
    For iCount2 = 0 To fldField1.Properties.Count - 1
      On Error Resume Next
      fldField2.Properties(iCount2).Value = fldField1.Properties(iCount2).Value
      fldField2.Properties(iCount2).Properties("Inherited") = fldField1.Properties(iCount2).Inherited
      On Error GoTo 0
    Next
    tdef2.Fields.Append fldField2
  Next iCount
  dbConvert.TableDefs.Append tdef2
 
  'Copy Records
  dbConvert.Execute ("INSERT INTO NewTable SELECT * FROM DBaseFile")
 
  'You should delete the attatchment to the DBase file here:
 
  dbConvert.Close
  wrkJet.Close
End Sub


0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

The canonical version of this article is on my web site here: http://iconoun.com/articles/collisions/ A companion presentation is available here: http://iconoun.com/articles/collisions/Unicode_Presentation.pdf
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Viewers will learn the different options available in the Backstage view in Excel 2013.

757 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

21 Experts available now in Live!

Get 1:1 Help Now