944,113 Members | Top Members by Rank

Ad:
Jul 5th, 2007
0

Urgent Help please in Database

Expand Post »
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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Naveed_Cn is offline Offline
10 posts
since Jun 2007
Jul 6th, 2007
0

Re: Urgent Help please in Database

You have to copy the code of OpenDatabase as well.
Reputation Points: 769
Solved Threads: 128
Banned
ithelp is offline Offline
1,910 posts
since May 2006
Jul 6th, 2007
0

Re: Urgent Help please in Database

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Naveed_Cn is offline Offline
10 posts
since Jun 2007
Jul 7th, 2007
0

Re: Urgent Help please in Database

can you please specify what exactly is the error you are getting, for my reference.
Featured Poster
Reputation Points: 665
Solved Threads: 427
Posting Genius
debasisdas is offline Offline
6,406 posts
since Feb 2007
Jul 7th, 2007
0

Re: Urgent Help please in Database

Click to Expand / Collapse  Quote originally posted by Naveed_Cn ...
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.
Last edited by AV Manoharan; Jul 7th, 2007 at 9:31 am.
Reputation Points: 10
Solved Threads: 9
Junior Poster
AV Manoharan is offline Offline
166 posts
since Jun 2007
Jul 8th, 2007
0

Re: Urgent Help please in Database

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Naveed_Cn is offline Offline
10 posts
since Jun 2007
Jul 8th, 2007
0

Re: Urgent Help please in Database

Click to Expand / Collapse  Quote originally posted by Naveed_Cn ...
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.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
kristinaswan is offline Offline
4 posts
since Dec 2006
Jul 11th, 2007
0

Re: Urgent Help please in Database

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
Reputation Points: 34
Solved Threads: 10
Junior Poster
manoshailu is offline Offline
105 posts
since Jun 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Multicolumn combo box using win32 API
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Help me to read the files of Real Player (RM,RAM...etc)





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC