Wrox Programmer Forums
|
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 14th, 2010, 07:03 AM
Authorized User
 
Join Date: Mar 2008
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default VB6 Database

Using the code from J. Connell's book VB6 DataBase programming (page 418) I have written and get to work, this program to design a database; it works fine as a stand alone program but when I copy it into an exsisting program it always fails on the line:-

Set db = DBEngine.Workspaces(0).CreateDatabase(dbName, dbLangGeneral)

giving the message that an object is required. But this listing works fine on its own! Where am I going wrong please?
The exsisting program is just a program to write to and delete a files in a database program and I now want to clear the files and start over.
Can you help a poor bloke who did have a nice head of hair before he started this program!!
Tony
__________________
A R Bradley
 
Old February 14th, 2010, 09:27 AM
Authorized User
 
Join Date: Mar 2009
Posts: 49
Thanks: 0
Thanked 8 Times in 8 Posts
Default

Did you remember to add a reference to DAO in your new program? In old/example program goto project>references and see which version of DAO is selected. Then in new, add that reference...



Good Luck
 
Old February 15th, 2010, 12:33 PM
Authorized User
 
Join Date: Mar 2008
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default ukbrad

Thanks for the reply; yes I did check the references and included the one that I had inserted on the first program. Sti;; no luck
__________________
A R Bradley
 
Old February 15th, 2010, 10:10 PM
Authorized User
 
Join Date: Mar 2009
Posts: 49
Thanks: 0
Thanked 8 Times in 8 Posts
Default

Well without seeing all the relavent code it is kind of hard to tell but from what I get you are saying is that you basically cut and pasted this code from an example and cannot make it work. Then you have checked your references and you say they are in order. Have you set breakpoints and used F8 to walk through the code to see if all your variables are in order?



Good Luck
 
Old February 16th, 2010, 10:54 AM
Authorized User
 
Join Date: Mar 2008
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default ukbrad

Yes, done all that; the program always fail at the same point. I have checked all the variables and they seem to be OK. I think I could include a copy of the program if you think that would help - otherwise I'm stumped!
__________________
A R Bradley
 
Old February 17th, 2010, 12:51 AM
Authorized User
 
Join Date: Mar 2009
Posts: 49
Thanks: 0
Thanked 8 Times in 8 Posts
Default

Okay, I just tried it with the DAO 3.6 driver and it worked like a champ...
Code:
Dim DB As DAO.Database
 
Set DB = DBEngine.Workspaces(0).CreateDatabase("C:\z\test.mdb", dbLangGeneral)
so last question I have is did you Dim DB As DAO.Database?



Good Luck
 
Old February 17th, 2010, 10:19 AM
Authorized User
 
Join Date: Mar 2008
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default ukBrad

I re-programed my DIM statement to DIM DB As DAO.Database and tried it with DAO3.6 driver and get a new fault - it now won't set the DBName line. I've (tried to) include a copy of the code to see if that helps. I'm about to retire and take up street cleaning!
I really am most grateful for all your time and trouble
Tony B

code
Option Explicit
Private Sub Form_Activate()
DBName = "Charter.mdb"
Dim DB As DAO.Database
Dim tblDef As TableDef
Dim fldDef As Field
Dim indx As Index
If MsgBox("Really delete all files?", vbOKCancel + vbCritical, "Warning Deletes ALL Files") = vbOK Then
Call DeleteFiles
End If
End Sub

Private Sub DeleteFiles()
If (Len(Dir(DBName))) > 0 Then 'Checks if there is an existing file
Kill DBName ' and removes any that file
End If
Set DB = DBEngine.Workspaces(0).CreateDatabase(DBName, dbLangGeneral)
Call CreateContactTable
MsgBox ("Datebase successfully created.")
'--- Please ensure that the file "Micosoft DAO 3.51 Object Library is ticked in Project > References.---
End Sub

Public Sub CreateContactTable()
'--Create contact table here--

Set tblDef = DB.CreateTableDef("Charter")
'--Create the fields in the charter table--
Set fldDef = tblDef.CreateField("Title", dbText, 5)
tblDef.Fields.Append fldDef
Set fldDef = tblDef.CreateField("F_Name", dbText, 12)
tblDef.Fields.Append fldDef
Set fldDef = tblDef.CreateField("S_Name", dbText, 30)
tblDef.Fields.Append fldDef
Set fldDef = tblDef.CreateField("Club", dbText, 30)
tblDef.Fields.Append fldDef
Set fldDef = tblDef.CreateField("Guest_of", dbText, 30)
tblDef.Fields.Append fldDef
Set fldDef = tblDef.CreateField("Table", dbText, 2)
tblDef.Fields.Append fldDef
Set fldDef = tblDef.CreateField("Number", dbLong, 4)
fldDef.Attributes = dbAutoIncrField
tblDef.Fields.Append fldDef
DB.TableDefs.Append tblDef

'--Add the index keys--
Set indx = tblDef.CreateIndex("iclub")
indx.Fields.Append indx.CreateField("S_Name")
indx.Fields.Append indx.CreateField("F_Name")
tblDef.Indexes.Append indx
End Sub

/code
__________________
A R Bradley
 
Old February 17th, 2010, 10:38 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

Bradley:

You need to pass DB to CreateContactTable.
Rigth now it only lives on the first sub (Form_Activate) but the variable not live on the other.

Another way is to move DB to an upper part, so the scope will be longer.
__________________
HTH

Gonzalo


================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the
proof.
================================================== =========
 
Old February 17th, 2010, 09:25 PM
Authorized User
 
Join Date: Mar 2009
Posts: 49
Thanks: 0
Thanked 8 Times in 8 Posts
Default

and to specify the full path...



Good Luck
 
Old February 18th, 2010, 11:18 AM
Authorized User
 
Join Date: Mar 2008
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default ukbrad

Sorry, I do not understand the last reply.
If I run the program as in the listing I sent, I get the message 'Variable not defined' for the line
Code
DBName = "Charter.mdb"
/code
Where Charter is the name of the Database I am trying to build. If I run the program without using the driver DAO 3.6 the program fails at
code
Set tblDef = DB.CreateTableDef("Charter")
/code
I do seem to be a lot of trouble for which I am very sorry; I am only a novice at this programing lark!
Tony Bradley
__________________
A R Bradley





Similar Threads
Thread Thread Starter Forum Replies Last Post
database and vb6 Probie VB Databases Basics 3 August 2nd, 2007 01:14 PM
Help With Searching Database (VB6.net) colm VB Databases Basics 0 June 5th, 2007 03:17 PM
Database Printing Recordset VB6 Hondacars VB How-To 1 March 11th, 2006 06:15 AM
URGENT help needed with VB6 database bassace VB Databases Basics 24 June 13th, 2005 01:08 PM
Database problems with mySQL and VB6 rgtuplin Pro VB 6 3 February 4th, 2004 04:06 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.