connection problem

this is the part of code for the connection
it is a module
pub lic connectDB()
on error resume next
Set CN= New connectio
DBpath=App.path & "\DBname.mdb

with CN
.Command time out=5
. connection string=provider =microsoft.jet.oledb4.0
data source="& DBpath & "; persist security information= false"
.open
end with
end sub

the other code that is highlighted is the class initialize co in the variiouse classes that i have created.
the code is.
Private sub class_initialise
dim strStudent as string
strStudent= "select * from student"
Call connect db
set rsStudent = New recordset
rsStudent.opoen strStudent, CN, Adopenkeyset, adlockoptimistic
end sub
Thanks in advance
[785 byte] By [odote] at [2007-11-20 0:41:22]
# 1 Re: connection problem
Dear Odote,

PLease remember few thing for connection. It is very simple to connect to an access database with Jet OLEDB 4.0. See the example below

1st Define the Command, Connection & Recordset objects as

Dim CN as New ADODB.Connection
Dim CMD as New ADODB.Command
DIM Rst as New ADODB.Recordset

In the load event of the form we use the following (Most Simplest)

With cn
.Provider = "Microsoft.Jet.Oledb.4.0"
.Open "Path & DatabaseName"
End With

With CMD
.Active Connection = Cn
.Command Type = adCMDText
.Command Text = "Select * from Student"
end with

set rst = cmd.execute

On running the above simple code you get the recordset (RST) filled with Data from the Table student if there is any record.

Follow this simple method. Make a connection then use the command object to connect and fill the recorset.

Hope you can now modify your code accordingly.

Regards
Amarjit
amarjitamarNew at 2007-11-9 19:56:54 >