Solved

dBase to Access

Posted on 1997-05-21
3
402 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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

828 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