Results 1 to 2 of 2
  1. #1
    Join Date
    May 2004
    Posts
    1

    Unanswered: HELP!! How to create Dbase5 dbf in VB6???

    I'm trying to create a one-row dBase5 file in plain VB6. I am using DAO but can use other Microsoft libs (don't want to install 3rd-party libs/controls).

    I'm creating the TableDef on the fly, adding fields.
    I believe I am missing something to get the RecordSet (underlying dbf file) created.
    Can someone tell me what I'm missing to actually get the widget.dbf file created?

    Simple code is:

    Public myWS As Workspace
    Public mydb As Database
    Public myTDef As TableDef
    Public myRS As Recordset
    Public myFld As Field

    Set mydb = OpenDatabase("C:\TESTDIR\", False, 0, "DBase 5.0;")
    Set myTDef = mydb.CreateTableDef()
    With myTDef
    .Fields.Append .CreateField("PartDesc", dbText, 8)
    .Fields.Append .CreateField("inv1", dbInteger, 4)
    .Fields.Append .CreateField("inv2", dbInteger, 4)
    .Fields.Append .CreateField("inv3", dbInteger, 4)
    .Fields.Append .CreateField("inv4", dbInteger, 4)
    End With
    Set myRS = mydb.OpenRecordset("Widget.dbf", dbOpenTable)
    With myRS
    .AddNew
    !PartDesc = "Widget"
    !inv1 = 4
    !inv2 = 3
    !inv3 = 6
    !inv4 = 1
    .Update
    End With

    mydb.TableDefs.Append myTDef
    mydb.Close

  2. #2
    Join Date
    May 2004
    Posts
    1

    Missing lines

    Dim myWS As Workspace
    Dim mydb As Database
    Dim myTDef As TableDef
    Dim myRS As Recordset
    Dim myFld As Field

    Set mydb = OpenDatabase("C:\TESTDIR", False, 0, "DBase 5.0;")
    'Following line need to be changed
    Set myTDef = mydb.CreateTableDef("Widget.dbf")
    With myTDef
    .Fields.Append .CreateField("PartDesc", dbText, 8)
    .Fields.Append .CreateField("inv1", dbInteger, 4)
    .Fields.Append .CreateField("inv2", dbInteger, 4)
    .Fields.Append .CreateField("inv3", dbInteger, 4)
    .Fields.Append .CreateField("inv4", dbInteger, 4)

    End With
    'Following line you were missing
    mydb.TableDefs.Append myTDef
    Set myRS = mydb.OpenRecordset("Widget.dbf", dbOpenTable)
    With myRS
    .AddNew
    !PartDesc = "Widget"
    !inv1 = 4
    !inv2 = 3
    !inv3 = 6
    !inv4 = 1
    .Update
    End With

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •