Hi Everyone
Please anyone tell me how can I use the following code in vb6 Module.
Dim db As Database
Dim rs As Recordset

Private Sub Form_Load()
Set db = OpenDatabase("C:\MyDatabase.mdb")
End Sub

Thanks in advance

You have to copy the code of OpenDatabase as well.

Hi
I tried four five times but it's not working, its show "Run Time erorr No 91". please write to me in detals.

thanks in advance.

can you please specify what exactly is the error you are getting, for my reference.

Hi Everyone
Please anyone tell me how can I use the following code in vb6 Module.
Dim db As Database
Dim rs As Recordset

Private Sub Form_Load()
Set db = OpenDatabase("C:\MyDatabase.mdb")
End Sub

Thanks in advance

The above program code is correct provided, there exists MyDatabase.mbd in C:\

If it exists try the following:

Private Sub Form_Load()
Dim db As Database
Dim rs As Recordset
Set db = OpenDatabase("C:\MyDatabase.mdb")
End Sub

If the above works then it is a case of Scope rule. Get back to me.

Hi Friends
Actually I m working on a database project. I am using in this project D.A.O 3.6 Object Library. I added lots of forms absolutely for many purposes. Now the problem I faced is that for every form I have to write the following code.

Option Explicit
Dim db As Database
Dim rs As Recordset

Private Sub Form_Load()
Set db = OpenDatabase("C:\MyDatabase.mdb")
End Sub

I want to use one Module and set the above codes for all the forms.
I tried the following codes in Module but is showing "Error No 91"

Option Explicit
Dim db As Database

Public Function MyDataBase() As String
Set db = OpenDatabase("C:\MyDatabase.mdb")
End Function

Private Sub Command1_Click()
call MyDataBase
Set Tb = db.OpenRecordset("Select * From Table1")
End Sub

Please tell me any method that you think will solve my problem.
Regard,
Naveed

Hi Friends
Actually I m working on a database project. I am using in this project D.A.O 3.6 Object Library. I added lots of forms absolutely for many purposes. Now the problem I faced is that for every form I have to write the following code.

Option Explicit
Dim db As Database
Dim rs As Recordset

Private Sub Form_Load()
Set db = OpenDatabase("C:\MyDatabase.mdb")
End Sub

I want to use one Module and set the above codes for all the forms.
I tried the following codes in Module but is showing "Error No 91"

Option Explicit
Dim db As Database

Public Function MyDataBase() As String
Set db = OpenDatabase("C:\MyDatabase.mdb")
End Function

Private Sub Command1_Click()
call MyDataBase
Set Tb = db.OpenRecordset("Select * From Table1")
End Sub

Please tell me any method that you think will solve my problem.
Regard,
Naveed

Couldn't you just create a Standard Module and write the code there as a function and then call the function on all of your forms? Still be some coding involved, but you'd only ned 1 line instead of 5 on each form. Maybe I'm wrong.

hi,

"Module"

Public db As dao.Database 'Declare variable for database connection

Public Sub connectdatabase()
Set db = DBEngine.OpenDatabase("C:\MyDatabase.mdb") 'Set the connection path
End Sub

"Form"

Dim rb As dao.Recordset 'Declare variable for recordset

Private Sub Command1_Click()
Call connectdatabase ' call the module
Set rb = db.OpenRecordset("table1") specidfy the table to open recordset
rb.AddNew
rb(0) = "1"
rb(1) = "Success"
rb.Update
End Sub

regards
Shailu

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.