Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2005
    Posts
    2

    Unanswered: Error 424 - object required

    please help ....

    my friend has a sample code and have it tried to run ...

    i have reviewed the code, check the syntax but it keeps on having the
    RTE 424; object required message whenever i compile the program ...

    below is the code ...

    Private Sub Form_Load()
    ' call procedure create_database
    create_database
    End Sub

    Public Sub create_database()
    Set ws = DBEngine.Workspaces(0) 'set the DB engine workspace
    Set DB = ws.CreateDatabase(App.Path & "\Sampledb.mdb", dbLangGeneral) 'createdatabase
    Set DB = ws.OpenDatabase(App.Path & "\Sampledb.mdb") 'open database
    Create_CardHolder_Table 'call create table
    MsgBox "DB Successfully Created!!"
    End Sub

    'Procedure: To create a table at runtime
    Public Sub Create_CardHolder_Table()

    Dim i As Integer
    '------Cardholder--------------
    Dim TDCardHolder As TableDef 'obj for tabledef
    Dim FLDcardHolder(7) As Field 'obj for fields
    Dim CardIDIndex As Index 'obj for index
    Dim CardIDFLD As Field 'obj for filed to set the index for a field

    ''------------Create Cardholder Table--------------------
    'create a table
    Set TDCardHolder = DB.CreateTableDef("Cardholder")
    Private Sub Form_Load()
    ' call procedure create_database
    create_database
    End Sub

    Public Sub create_database()
    Set ws = DBEngine.Workspaces(0) 'set the DB engine workspace
    'Set DB = ws.CreateDatabase(App.Path & "\Sampledb.mdb", dbLangGeneral) 'createdatabase
    Set DB = ws.OpenDatabase(App.Path & "\Sampledb.mdb") 'open database
    Create_CardHolder_Table 'call create table
    MsgBox "DB Successfully Created!!"
    End Sub

    'Procedure: To create a table at runtime
    Public Sub Create_CardHolder_Table()

    Dim i As Integer
    '------Cardholder--------------
    Dim TDCardHolder As TableDef 'obj for tabledef
    Dim FLDcardHolder(7) As Field 'obj for fields
    Dim CardIDIndex As Index 'obj for index
    Dim CardIDFLD As Field 'obj for filed to set the index for a field

    ''------------Create Cardholder Table--------------------
    'create a table
    Set TDCardHolder = DB.CreateTableDef("Cardholder") * error in this line ...
    'create a field 'ID' of Text datatype with the filed size of 8
    Set FLDcardHolder(0) = TDCardHolder.CreateField("ID", dbText, 8)
    'set required as true as this is Primary key FLDcardHolder(0).Required = True
    'set allow zero lenghth to false
    FLDcardHolder(0).AllowZeroLength = False
    'Similarly do for other fields
    'datatype can be dbtext for text fileds
    'dbdate for date fileds
    'dblong for long datatype etc.
    'check the filed type in msdn help for more datatypes

    Set FLDcardHolder(1) = TDCardHolder.CreateField("Name", dbText, 25)
    FLDcardHolder(1).Required = True
    FLDcardHolder(1).AllowZeroLength = False

    Set FLDcardHolder(2) = TDCardHolder.CreateField("DateofIssue", dbDate)
    FLDcardHolder(2).Required = False

    Set FLDcardHolder(3) = TDCardHolder.CreateField("Gender", dbText, 6)
    FLDcardHolder(3).Required = True
    FLDcardHolder(3).AllowZeroLength = False

    Set FLDcardHolder(4) = TDCardHolder.CreateField("DateofBirth", dbDate)
    FLDcardHolder(4).Required = True

    Set FLDcardHolder(5) = TDCardHolder.CreateField("Address", dbText, 60)
    FLDcardHolder(5).Required = False
    FLDcardHolder(5).AllowZeroLength = True


    Set FLDcardHolder(6) = TDCardHolder.CreateField("Pincode", dbText, 6)
    FLDcardHolder(6).Required = False
    FLDcardHolder(6).AllowZeroLength = True

    Set FLDcardHolder(7) = TDCardHolder.CreateField("Phone", dbText, 12)
    FLDcardHolder(7).Required = False
    FLDcardHolder(7).AllowZeroLength = True

    'append all fields to the table
    For i = 0 To 7
    TDCardHolder.Fields.Append FLDcardHolder(i)
    Next i
    'create an index for the filed 'ID'
    Set CardIDIndex = TDCardHolder.CreateIndex("ID")
    CardIDIndex.Primary = True 'set primary key as true for making it as primary key
    CardIDIndex.Unique = True 'set unique as true for making any filed as unique

    'append the index filed to the table's index
    Set CardIDFLD = CardIDIndex.CreateField("ID")
    CardIDIndex.Fields.Append CardIDFLD
    TDCardHolder.Indexes.Append CardIDIndex
    'append the table to the database
    DB.TableDefs.Append TDCardHolder

    'reset all reference variables to nothing
    Set CardIDIndex = Nothing
    Set CardIDFLD = Nothing
    Set TDCardHolder = Nothing
    For i = 0 To 7
    Set FLDcardHolder(i) = Nothing
    Next i
    End Sub


    thanks,
    jojo

  2. #2
    Join Date
    May 2004
    Posts
    97
    VB is very forgiving. It will tell you exactly where your error is, and point to the line with the error. But, you did not relay that information to us.

    If you have any error traps in your code (on error go...) and active (without the code running into a 'resume') then it will NOT give you friendly messages. To debug your code be sure ou have no 'on error' statements in your code, and tell us which line the error points to.

    Usually, your error means that you have not properly Dim'd a variable as the object.

Posting Permissions

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