Results 1 to 5 of 5

Thread: problem with this insert statment in vba

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Arrow problem with this insert statment in vba

    Hi guys i got vba code that suppose to write table name ,column name , rquired ,feild type and feild size
    to an external db. The first part of this code write tables naem to external db and it is working well.
    I get the following error when i press the button on my form :

    Code:
    Run-time error '424':
    
    Object required
    and when i click on debut it points to this part with yellow collor.

    Code:
     metadb.Execute " Insert Into SysColumns(tablename,columnname,required,type,lenght) " & _
        " Values ('" & TableDef.Name & "','" & Feild.Name & "'," & Feild.Required & ",'" & FieldType(Feild.Type) & "'," & Feild.Size & ")"
    I be happy if some one help me fix this erro.Thanks

    my complete code

    Code:
    Sub InsertSystemCatalogPopulation(db As Database, metadb As Database)
    
    '''now locating all the non system tables in current db  and then writing it
    '''to systables table
    For Each tbl In db.TableDefs
    
    ''' excluding the system tables
            If Left(tbl.Name, 4) <> "MSys" Then
            ''' writing the tables name to systables
            
                metadb.Execute " Insert Into SysTables(TableName) Values ('" & tbl.Name & "')"
            End If
        Next tbl
        
        MsgBox (" All tables names coped to systables system cataloge ")
        
      '''###################################################################################
        
        ''' now we go find all non syste feilds in the current db and then writing ity
        '''  to syscolumns
        
        For Each TableDef In CurrentDb.TableDefs
    '''this if statment remove the system feilds
     If Left(TableDef.Name, 4) <> "Msys" Then
       For Each Field In TableDef.Fields
         
        metadb.Execute " Insert Into SysColumns(tablename,columnname,required,type,lenght) " & _
        " Values ('" & TableDef.Name & "','" & Feild.Name & "'," & Feild.Required & ",'" & FieldType(Feild.Type) & "'," & Feild.Size & ")"
         
        Next Field
      End If
    Next TableDef
    
    End Sub
    
    
    
    
    Function FieldType(intType As Integer) As String
    
        Select Case intType
            Case dbBoolean
                FieldType = "dbBoolean"
            Case dbByte
                FieldType = "dbByte"
            Case dbInteger
                FieldType = "dbInteger"
            Case dbLong
                FieldType = "dbLong"
            Case dbCurrency
                FieldType = "dbCurrency"
            Case dbSingle
                FieldType = "dbSingle"
            Case dbDouble
                FieldType = "dbDouble"
            Case dbDate
                FieldType = "dbDate"
            Case dbText
                FieldType = "dbText"
            Case dbLongBinary
                FieldType = "dbLongBinary"
            Case dbMemo
                FieldType = "dbMemo"
            Case dbGUID
                FieldType = "dbGUID"
        End Select
    
    End Function

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: problem with this insert statment in vba

    Why are you trying to write to the system tables telling them that there are tables in the db? If you create the tables it
    will automatically write to the systables the tables and their schema.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Arrow Re: problem with this insert statment in vba

    Quote Originally Posted by RobDog888
    Why are you trying to write to the system tables telling them that there are tables in the db? If you create the tables it
    will automatically write to the systables the tables and their schema.

    well it is systable in external db that my code generate that systable!

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: problem with this insert statment in vba

    Oh, ok. I was thinking MSYS tables.

    You have a mispelled object word - Feild.Name.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Arrow Re: problem with this insert statment in vba

    Quote Originally Posted by RobDog888
    Oh, ok. I was thinking MSYS tables.

    You have a mispelled object word - Feild.Name.
    opss . thank u i fixed it!

Posting Permissions

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



Click Here to Expand Forum to Full Width