954,535 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Create tables in access database by DAO liberary

[TEX]
hi every one
i have problem in database
if i want to create 7 tables by DAO liberary the name of the tables are :
vn,itm,ctm,vst,sal,vnd & tin
i have created tables as :

Set db = CreateDatabase("WORKS.MDB", dbLangGeneral)

db.Execute "CREATE TABLE vn(vn_nm text (30),vn_add text (100),vn_bo text (30),vn_tel text (30),vn_reg text (15),vn_rec text (15),vn_fax text (15),vn_eml text (100),vn_nte memo)"

Set db = DBEngine.Workspaces(0).OpenDatabase("works.mdb", 2)
Set vn = db.OpenRecordset("VN", 2)

it is an example of creating one of tables so is it true or not?

but when i do this in all tables there are an error is:

run-time error'91':
Object variable or with block variable not set

please i want the help
and finally thanks

ahmed elweshahy
Newbie Poster
18 posts since Apr 2007
Reputation Points: 6
Solved Threads: 0
 

i have used amodule to identify the following:
Global db As Database
Global vn As Recordset
Global ctm As Recordset
Global itm As Recordset
Global tin As Recordset
Global sal As Recordset
Global vst As Recordset
Global vnd As Recordset

ahmed elweshahy
Newbie Poster
18 posts since Apr 2007
Reputation Points: 6
Solved Threads: 0
 

G'd afternoon ahmed!!
The error you get is because you need to initialize one or more of your variables before you use them. Something like this:

Global db As NEW Database
Global vn As New Recordset


By the way, you should recheck if you need all those recordsets at the same time. I don't know about your code, but it seems like you can reuse the same dataset for all the job.

Good luck
Estuardo

Estuardo
Newbie Poster
13 posts since Jul 2005
Reputation Points: 10
Solved Threads: 0
 

hi Esturado
thank you
but i want to do the follwing
when the user press or click the button , for example the table which called vn became connected to the vb6 and when the user click anothr button another table connected to vb6 this is my problem that
when i connect all tables with vb6 , two tables are only connected and other tables aren't connect although i connect all tables
remark: i initalize every thing true
two tables are connected but others not connect.

my initialization are:
Global db As Database
Global vn As Recordset
Global ctm As Recordset
Global itm As Recordset
Global tin As Recordset
Global sal As Recordset
Global vst As Recordset
Global vnd As Recordset
in module
there aren't for example :
Global vn as new recordset
Global db as new database
and thank you

ahmed elweshahy
Newbie Poster
18 posts since Apr 2007
Reputation Points: 6
Solved Threads: 0
 
my initialization are: Global db As Database Global vn As Recordset Global ctm As Recordset Global itm As Recordset Global tin As Recordset Global sal As Recordset Global vst As Recordset Global vnd As Recordset in module there aren't for example : Global vn as new recordset Global db as new database and thank you

Don't use Global because it eat lots of memory instead use Public and don't declare your recordset at one time because again it eat lots of memory instead declare it only when needed.

not Global db As Database

instead...

Public db As Database

to open the database use this
Set db=OpenDatabase(put the location of your vb)
i.e.
Set db=OpenDatabase("C:\Work\Work.mdb")

or...
Set db=OpenDatabase(App.Path & "\Work.mdb")

then put this code to the command button where you want to open a table

Dim vn as Recordset

Set vn=db.Openrecordset("select * from [vn]")

jireh
Posting Whiz
316 posts since Jul 2007
Reputation Points: 11
Solved Threads: 49
 

Hi Ahmed,

First Create the Database and then Open It.

Syntax for creating Database is :

DBEngine.CreateDatabase "Works.mdb", dbLangGeneral

After Creating Open the Database:

Set DB = DBEngine.OpenDatabase("Works.mdb", False, False)

Regards
Veena

QVeen72
Posting Shark
950 posts since Nov 2006
Reputation Points: 84
Solved Threads: 143
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You