I'm looking to allow users to create a custom table by editing an existing table or creating a new table from scratch. Can VB allow for a createTable - like property?
yes u can defintely create Access database and tables through VB. Use DAO model to do that.
This code will do that:
Private wrkDefault As Workspace
Private dbsNew As Database
Private tdfNew As New TableDef
Set wrkDefault = DBEngine.Workspaces(0)
Set dbsNew = wrkDefault.CreateDatabase("MDB.mdb", _
dbLangGeneral, dbEncrypt)
Set dbsNew = wrkDefault.OpenDatabase("MDB.mdb", True, False) 'open the created Database
Set tdfNew = dbsNew.CreateTableDef("TableName"
with tdfNew
.Fields.Append .CreateField("Feild1" 'Create a new field
end with
dbsNew.TableDefs.Append tdfNew 'add the table to the DB
dbsNew.Close 'close db
The above will create a database, table and field.
Hope this works.
Let me know if u need more information.
Thanks
PS: Make sure to have a referance MS DAO 3.6 Library. Murali Bala
I have implemented the code but I get a run time error when the code hits the line:
dbsNew.TableDefs.Append tdfNew 'add the table to the DB
the eroor is :
Run time error '3259':
Invalid field data type
Any ideas why this is occuring? The only real change I made to this code is I referenced a pre-existing database in the line:
Set dbsNew = wrkDefault.CreateDatabase("MDB.mdb", _
dbLangGeneral, dbEncrypt)...I don't need to create a database, I just need to add a table to it.
OK, now here's the last step, I want to fill this new table with the contents of a dbgrid...I have the contents of the dbgrid saved into a table named template. I want to save the contents of template/dbgrid as NEW_Table and then clear the contents of template so that I can repeat this process.
If you have many records in Template table you can iterate through them using Do while Not EOF..and then writing it to the New table. Hope this Helps..
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.