Log inUsernamePassword
Log me on automatically each visit    
Register
Register
Log in to check your private messages
Log in to check your private messages
Visual Basic Forum for Visual Basic Programmers VB Forum Index » Database & Reporting

Post new topic   Reply to topic
User-Defined type not defined?
View previous topic :: View next topic  
Author Message
jozin
Newbie


Joined: 25 Jul 2005
Posts: 7

PostPosted: Aug 15th, 2005 03:17 AM    Post subject: User-Defined type not defined? Reply with quote

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
View user's profile Send private message
dougthomas
Moderator


Joined: 27 Jul 2005
Posts: 271
Location: Essex, UK

PostPosted: Aug 15th, 2005 07:26 AM    Post subject: Reply with quote

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
View user's profile Send private message
jozin
Newbie


Joined: 25 Jul 2005
Posts: 7

PostPosted: Aug 15th, 2005 09:31 PM    Post subject: Reply with quote

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
View user's profile Send private message
jozin
Newbie


Joined: 25 Jul 2005
Posts: 7

PostPosted: Aug 15th, 2005 09:35 PM    Post subject: Reply with quote

Just a follow up Doug, what is included in my Components window is Microsoft ADO Data Control not DAO.
Back to top
View user's profile Send private message
dougthomas
Moderator


Joined: 27 Jul 2005
Posts: 271
Location: Essex, UK

PostPosted: Aug 15th, 2005 11:47 PM    Post subject: Reply with quote

Hi again,

Do you have Access installled? or are you trying to use another db Manager ?

Regards Doug
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Visual Basic Forum for Visual Basic Programmers VB Forum Index » Database & Reporting All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Visual Basic Forum runs phpBB | Forum Template © iOptional
VB Resources | SSL | Visual Basic