Urgent Help please in Database

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Jun 2007
Posts: 10
Reputation: Naveed_Cn is an unknown quantity at this point 
Solved Threads: 0
Naveed_Cn Naveed_Cn is offline Offline
Newbie Poster

Urgent Help please in Database

 
0
  #1
Jul 5th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 1,857
Reputation: ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all 
Solved Threads: 120
ithelp's Avatar
ithelp ithelp is offline Offline
Posting Virtuoso

Re: Urgent Help please in Database

 
0
  #2
Jul 6th, 2007
You have to copy the code of OpenDatabase as well.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 10
Reputation: Naveed_Cn is an unknown quantity at this point 
Solved Threads: 0
Naveed_Cn Naveed_Cn is offline Offline
Newbie Poster

Re: Urgent Help please in Database

 
0
  #3
Jul 6th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 2,132
Reputation: debasisdas will become famous soon enough debasisdas will become famous soon enough 
Solved Threads: 132
debasisdas's Avatar
debasisdas debasisdas is offline Offline
Postaholic

Re: Urgent Help please in Database

 
0
  #4
Jul 7th, 2007
can you please specify what exactly is the error you are getting, for my reference.
Share your Knowledge.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 166
Reputation: AV Manoharan is an unknown quantity at this point 
Solved Threads: 9
AV Manoharan AV Manoharan is offline Offline
Junior Poster

Re: Urgent Help please in Database

 
0
  #5
Jul 7th, 2007
Originally Posted by Naveed_Cn View 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
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 10
Reputation: Naveed_Cn is an unknown quantity at this point 
Solved Threads: 0
Naveed_Cn Naveed_Cn is offline Offline
Newbie Poster

Re: Urgent Help please in Database

 
0
  #6
Jul 8th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 4
Reputation: kristinaswan is an unknown quantity at this point 
Solved Threads: 1
kristinaswan kristinaswan is offline Offline
Newbie Poster

Re: Urgent Help please in Database

 
0
  #7
Jul 8th, 2007
Originally Posted by Naveed_Cn View Post
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 97
Reputation: manoshailu is an unknown quantity at this point 
Solved Threads: 10
manoshailu's Avatar
manoshailu manoshailu is offline Offline
Junior Poster in Training

Re: Urgent Help please in Database

 
0
  #8
Jul 11th, 2007
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
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for Visual Basic 4 / 5 / 6
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC