| View previous topic :: View next topic |
| Author |
Message |
jozin Newbie
Joined: 25 Jul 2005 Posts: 7
|
Posted: Aug 15th, 2005 03:17 AM Post subject: User-Defined type not defined? |
|
|
Hi everyone,
I want to create a database using a VB6 code. I tried to use the CREATEDATABASE command. But the error is: User-Defined type not defined.
Here is my code.
Private Sub Command1_Click()
Dim dbe As New DAO.DBEngine // the error is in this line
Dim db As DAO.Database
Set db = dbe.CreateDatabase("c:\NewDB.mdb", dbLangGeneral)
db.Close
Set db = Nothing
Set dbe = Nothing
End Sub
What is wrong with my code? Is there a better way to do it?
Can you please show me how to VB code on how to create a database and a table then delete it after using?
Any comment and suggestion is very much appreciated.
jozin |
|
| Back to top |
|
dougthomas Moderator
Joined: 27 Jul 2005 Posts: 271 Location: Essex, UK
|
Posted: Aug 15th, 2005 07:26 AM Post subject: |
|
|
Hi Josin,
You need to add a reference to Microsoft DAO Object Library into your Project. (from the References selection under the Project menu item)
You can use the .CreateTableDef, .CreateFields and .Fields.Append methods to define the Table, and TableDefs.Delete to delete it, something like:
| Code: |
Private Sub Command1_Click()
Dim dbe As New DAO.DBEngine
Dim db As DAO.Database
Dim tbl As TableDef
Set db = dbe.CreateDatabase("c:\NewDB.mdb", dbLangGeneral)
'
' Initialise the new Table (name tblTest)
'
Set tbl = db.CreateTableDef("tblTest")
'
' Define the fields in tblTest
'
tbl.Fields.Append tbl.CreateField("TextField", dbText)
tbl.Fields.Append tbl.CreateField("IntegerField", dbInteger)
tbl.Fields.Append tbl.CreateField("LongIntegerField", dbLong)
tbl.Fields.Append tbl.CreateField("DateField", dbDate)
'
' Add tblTest into the Database
'
db.TableDefs.Append tbl
'
'
'
' Now do whatever processing you want to do
'
'
'
db.TableDefs.Delete ("tblTest")
db.Close
Set db = Nothing
Set dbe = Nothing
End Sub
|
I found this code here: [link]
You may wish to take a look as it explains quite a lot.
Regards
Doug |
|
| Back to top |
|
jozin Newbie
Joined: 25 Jul 2005 Posts: 7
|
Posted: Aug 15th, 2005 09:31 PM Post subject: |
|
|
Hi Doug,
Thank you very much for your help. The thing is the Microsoft DAO Object Library is not included in the components window under project menu. Is there a way to upload or include the MS DAO Object Library in the components window so I can add it in my project?
jozin. =D |
|
| Back to top |
|
jozin Newbie
Joined: 25 Jul 2005 Posts: 7
|
Posted: Aug 15th, 2005 09:35 PM Post subject: |
|
|
| Just a follow up Doug, what is included in my Components window is Microsoft ADO Data Control not DAO. |
|
| Back to top |
|
dougthomas Moderator
Joined: 27 Jul 2005 Posts: 271 Location: Essex, UK
|
Posted: Aug 15th, 2005 11:47 PM Post subject: |
|
|
Hi again,
Do you have Access installled? or are you trying to use another db Manager ?
Regards Doug |
|
| Back to top |
|
|