Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Creating Access database with VB6

Creating Access database with VB6

Scheduled Pinned Locked Moved Database
databasehelpbusinesssales
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 12161521
    wrote on last edited by
    #1

    I am creating a database in Access with 3 tables. Each table has different number of columns or fields. I get an error when creating more than 8 fields. If I comment out the other fields, then everything works great. Can anyone help? Code is as follows: Dim FileName As String, strConn As String Dim adoCat As ADOX.Catalog, adoTable As ADOX.Table Dim tblCollection As Collection Dim Script As Object 'check and/or build DB Set Script = CreateObject("Scripting.filesystemobject") If Script.FolderExists("C:\Business Pro") Then 'folder is in place...move on If Dir("C:\Business Pro\BusinessPro.mdb") = "" Then 'dir not in place...build lblPB.Caption = "No database found. Creating database..." FileName = "C:\Business Pro\BusinessPro.mdb" 'create instance of ADOX-object Set adoCat = New ADOX.Catalog 'creat instance of Collection-object Set tblCollection = New Collection Set adoTable = New ADOX.Table strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & FileName & ";" 'create the db adoCat.Create (strConn) 'name table tblCollection.Add "Customer_Contacts" With adoTable .Name = "Customer_Contacts" 'name the table .Columns.Append "CustID", adInteger 'create a field in primary key .ParentCatalog = adoCat 'set Parent catalog .Columns("CustID").Properties("AutoIncrement").Value = True .Keys.Append "PrimaryKey", adKeyPrimary, "CustID" 'append primary key 'add rest of fields .Columns.Append "FirstName", adWChar .Columns.Append "LastName", adWChar .Columns.Append "Address", adWChar .Columns.Append "City", adWChar .Columns.Append "State", adWChar .Columns.Append "Zip", adLongVarWChar, 5 .Columns.Append "PhoneNumber", adLongVarWChar, 10 End With 'add table to mdb adoCat.Tables.Append adoTable 'create 2nd table Set adoTable = New ADOX.Table 'name table tblCollection.Add "Labor_Rates" With adoTable .Name = "Labor_Rates" 'name the table .Columns.Append "ID", adInteger 'create a field in primary key .ParentCatalog = adoCat 'set Parent catalo

    M CHill60C 2 Replies Last reply
    0
    • U User 12161521

      I am creating a database in Access with 3 tables. Each table has different number of columns or fields. I get an error when creating more than 8 fields. If I comment out the other fields, then everything works great. Can anyone help? Code is as follows: Dim FileName As String, strConn As String Dim adoCat As ADOX.Catalog, adoTable As ADOX.Table Dim tblCollection As Collection Dim Script As Object 'check and/or build DB Set Script = CreateObject("Scripting.filesystemobject") If Script.FolderExists("C:\Business Pro") Then 'folder is in place...move on If Dir("C:\Business Pro\BusinessPro.mdb") = "" Then 'dir not in place...build lblPB.Caption = "No database found. Creating database..." FileName = "C:\Business Pro\BusinessPro.mdb" 'create instance of ADOX-object Set adoCat = New ADOX.Catalog 'creat instance of Collection-object Set tblCollection = New Collection Set adoTable = New ADOX.Table strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & FileName & ";" 'create the db adoCat.Create (strConn) 'name table tblCollection.Add "Customer_Contacts" With adoTable .Name = "Customer_Contacts" 'name the table .Columns.Append "CustID", adInteger 'create a field in primary key .ParentCatalog = adoCat 'set Parent catalog .Columns("CustID").Properties("AutoIncrement").Value = True .Keys.Append "PrimaryKey", adKeyPrimary, "CustID" 'append primary key 'add rest of fields .Columns.Append "FirstName", adWChar .Columns.Append "LastName", adWChar .Columns.Append "Address", adWChar .Columns.Append "City", adWChar .Columns.Append "State", adWChar .Columns.Append "Zip", adLongVarWChar, 5 .Columns.Append "PhoneNumber", adLongVarWChar, 10 End With 'add table to mdb adoCat.Tables.Append adoTable 'create 2nd table Set adoTable = New ADOX.Table 'name table tblCollection.Add "Labor_Rates" With adoTable .Name = "Labor_Rates" 'name the table .Columns.Append "ID", adInteger 'create a field in primary key .ParentCatalog = adoCat 'set Parent catalo

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      I'm afraid you are really pushing your luck trying to get support for a language that has not been supported for more than a decade. You should download and use the free VB.net express.

      Never underestimate the power of human stupidity RAH

      U 1 Reply Last reply
      0
      • M Mycroft Holmes

        I'm afraid you are really pushing your luck trying to get support for a language that has not been supported for more than a decade. You should download and use the free VB.net express.

        Never underestimate the power of human stupidity RAH

        U Offline
        U Offline
        User 12161521
        wrote on last edited by
        #3

        I was just thinking of learning the .Net language and converting over and rewrite my whole program. I guess now is as good a time as any to do it. Thanks!

        M 1 Reply Last reply
        0
        • U User 12161521

          I was just thinking of learning the .Net language and converting over and rewrite my whole program. I guess now is as good a time as any to do it. Thanks!

          M Offline
          M Offline
          Mycroft Holmes
          wrote on last edited by
          #4

          I would recommend converting to c#, the learning curve will be marginally steeper but the learning resources are 2-3 time the amount of VB.net code.

          Never underestimate the power of human stupidity RAH

          1 Reply Last reply
          0
          • U User 12161521

            I am creating a database in Access with 3 tables. Each table has different number of columns or fields. I get an error when creating more than 8 fields. If I comment out the other fields, then everything works great. Can anyone help? Code is as follows: Dim FileName As String, strConn As String Dim adoCat As ADOX.Catalog, adoTable As ADOX.Table Dim tblCollection As Collection Dim Script As Object 'check and/or build DB Set Script = CreateObject("Scripting.filesystemobject") If Script.FolderExists("C:\Business Pro") Then 'folder is in place...move on If Dir("C:\Business Pro\BusinessPro.mdb") = "" Then 'dir not in place...build lblPB.Caption = "No database found. Creating database..." FileName = "C:\Business Pro\BusinessPro.mdb" 'create instance of ADOX-object Set adoCat = New ADOX.Catalog 'creat instance of Collection-object Set tblCollection = New Collection Set adoTable = New ADOX.Table strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & FileName & ";" 'create the db adoCat.Create (strConn) 'name table tblCollection.Add "Customer_Contacts" With adoTable .Name = "Customer_Contacts" 'name the table .Columns.Append "CustID", adInteger 'create a field in primary key .ParentCatalog = adoCat 'set Parent catalog .Columns("CustID").Properties("AutoIncrement").Value = True .Keys.Append "PrimaryKey", adKeyPrimary, "CustID" 'append primary key 'add rest of fields .Columns.Append "FirstName", adWChar .Columns.Append "LastName", adWChar .Columns.Append "Address", adWChar .Columns.Append "City", adWChar .Columns.Append "State", adWChar .Columns.Append "Zip", adLongVarWChar, 5 .Columns.Append "PhoneNumber", adLongVarWChar, 10 End With 'add table to mdb adoCat.Tables.Append adoTable 'create 2nd table Set adoTable = New ADOX.Table 'name table tblCollection.Add "Labor_Rates" With adoTable .Name = "Labor_Rates" 'name the table .Columns.Append "ID", adInteger 'create a field in primary key .ParentCatalog = adoCat 'set Parent catalo

            CHill60C Offline
            CHill60C Offline
            CHill60
            wrote on last edited by
            #5

            Some points that might help ... You're not defining the maximum size of the text columns so they are all defaulting to 255. Did you really want a Memo field for DaysOnJob? For that matter, shouldn't LaborRate be adDouble not adWChar? Or an integer - linking to Labor_Rates.ID Consider using the DAO library rather than the ADO extension library (which is not stable). On the subject of using VB6 - now is definitely the time to stop using it! But don't assume that VB.NET is the natural progression into .NET. C# is really worth considering. If not then MacDonald publish a book for programmers transitioning from VB6 (The one I had was "The Book of Visual Basic 2005", but that's well out of date now).

            U 1 Reply Last reply
            0
            • CHill60C CHill60

              Some points that might help ... You're not defining the maximum size of the text columns so they are all defaulting to 255. Did you really want a Memo field for DaysOnJob? For that matter, shouldn't LaborRate be adDouble not adWChar? Or an integer - linking to Labor_Rates.ID Consider using the DAO library rather than the ADO extension library (which is not stable). On the subject of using VB6 - now is definitely the time to stop using it! But don't assume that VB.NET is the natural progression into .NET. C# is really worth considering. If not then MacDonald publish a book for programmers transitioning from VB6 (The one I had was "The Book of Visual Basic 2005", but that's well out of date now).

              U Offline
              U Offline
              User 12161521
              wrote on last edited by
              #6

              Thanks for the pointers. I went about it all differently. I created the tables I need in Access 2007 and through code, I just copy the database to another directory. I found it to be less of a headache than creating all the tables through code. Thanks again :)

              CHill60C 1 Reply Last reply
              0
              • U User 12161521

                Thanks for the pointers. I went about it all differently. I created the tables I need in Access 2007 and through code, I just copy the database to another directory. I found it to be less of a headache than creating all the tables through code. Thanks again :)

                CHill60C Offline
                CHill60C Offline
                CHill60
                wrote on last edited by
                #7

                Yes - much less of a headache! :) One thing to watch out for .. if in the future you need to change the schema of the database after you have rolled it out to users you will need to consider how to amend existing data... but by then you will have upgraded to .net :laugh:

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups