Is there anyway to create and open databases at run-time?
Printable View
Is there anyway to create and open databases at run-time?
Sure, here's an example of Creating an Access DB at runtime using the DAO Objects:
------------------Code:Private Sub Command1_Click()
Dim oWork As Workspace
Dim oDatabase As Database
Dim oTable As TableDef
Dim oField As Field
Set oWork = Workspaces(0)
'Create an Empty Database
Set oDatabase = oWork.CreateDatabase("C:\NewDB.mdb", dbLangGeneral)
'Create a Table Object
Set oTable = oDatabase.CreateTableDef("Table1")
'Create a Field Object
Set oField = oTable.CreateField("Field1", dbText, 20)
'Add the Field to the Table Object
oTable.Fields.Append oField
'Add the Table Object to the Database
oDatabase.TableDefs.Append oTable
'All Done, Close and Release the Objects
oDatabase.Close
oWork.Close
Set oField = Nothing
Set oTable = Nothing
Set oDatabase = Nothing
Set oWork = Nothing
MsgBox "Database Created"
End Sub
Aaron Young
Analyst Programmer
[email protected]
[email protected]
Certified AllExperts Expert
Go to Project-->References and choose Microsoft DAO 3.5 Object Library or something like that. It should help
------------------
Visual Basic Programmer
------------------
PolComSoft
You will hear a lot about it.
Thanks a lot, both of you!!! I don't know what I'd do without all you people that know what you're doing.
Thanks for the reply, but I have run into another problem. I'm using VB 6 Learning Edition, and it doesn't seem to recognize Workspace, Database, TableDef, and Field as valid variable types. Is there anyway to get around this, or will I just need to upgrade.
In the above said method (post # 2) we must know how many fields we have....
what i am asking is user only knows the fields.....is there is any way to make like that ?
At a time can we make 2 tables in a mdb? (All rows to one table and columns to one table with its total value?)
User will only see as per attached image....but in coding only we going to make tables in one mdb.....
Please see and advice !!!
Thanks for reply.
Please advise, in this method can we convert Text1.text as field1 , text2.text as field2.....like that...?
Friends !
I have 3 tables (structure and samples records attached). Now I want to create the final report as attached.
Please guide me !!
thanking you in anticipation.
Please Help ME !!!