Transferring variables across forms in VB6

Thread Solved

Join Date: Jan 2008
Posts: 50
Reputation: lostandfound is an unknown quantity at this point 
Solved Threads: 1
lostandfound's Avatar
lostandfound lostandfound is offline Offline
Junior Poster in Training

Transferring variables across forms in VB6

 
0
  #1
Jan 20th, 2008
Hello,
I have been trying with no success to transfer a recordset from one form to another.
I have declared in Form1 that

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Public myRS As ADODB.Recordset

All works lovely in Form1
In Form2 when I use

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub cmdFail_Click(ByVal myRS As ADODB.Recordset)

I get an error message at runtime

Compile Error Procedure Declaration does not match description of event or procedure having the same name.
I have managed to get around the problem by stating all of my variables as Public in a Module, but from what I have read this may be poor practice.
Any help would be much appreciated.Thanks
P.S Does anybody find the ADO control even remotely easy to understand.
Ther are 10 types of people in the world. Those who do understand binary and those who don't!!
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 218
Reputation: hkdani is an unknown quantity at this point 
Solved Threads: 24
hkdani's Avatar
hkdani hkdani is offline Offline
Posting Whiz in Training

Re: Transferring variables across forms in VB6

 
0
  #2
Jan 20th, 2008
You should try using the form name first when using it from form2: e.g.
form1.MyRs

It's best to use class modules instead of regular modules. Class modules have better support for Data Objects.

Hank
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 50
Reputation: lostandfound is an unknown quantity at this point 
Solved Threads: 1
lostandfound's Avatar
lostandfound lostandfound is offline Offline
Junior Poster in Training

Re: Transferring variables across forms in VB6

 
0
  #3
Jan 21st, 2008
Nice one.Thanks for the reply.Having used this method with other types of variables I am sure this will work.I am working on a multiple form project and will try out this method on one of them.I will let you know how things go.
I would still be interested to know, if anyone can help , how to introduce the variable as a public variable from another form in the routine name ie

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub cmdCommand(ByVal introduce Public recordset)

Thanks very much for your reply. All suggestions help.
And thanks for the Class Module suggestion. I shall have a read.
Last edited by lostandfound; Jan 21st, 2008 at 5:53 pm. Reason: Add a bit,Spelling
Ther are 10 types of people in the world. Those who do understand binary and those who don't!!
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 300
Reputation: jireh is an unknown quantity at this point 
Solved Threads: 42
jireh's Avatar
jireh jireh is offline Offline
Posting Whiz

Re: Transferring variables across forms in VB6

 
0
  #4
Jan 21st, 2008
If you always use that function/procedure try to put that in a module so that anyone can access that procedure/function

Here's a sample...

Declare this in a module
Public Function dbOpenRecordSet(sqlcmd as String) as Recordset
1. if your database was not yet open, then open it.
2. open a recordset with the query in the sqlcmd (sqlcmd the variable who holds your query.
in your form...
Dim sqlcmd as String

sqlcmd = "select * from mytable"
dbOpenRecordSet(sqlcmd)
If Not dbOpenRecordset.EOF Then
put here what you want to the data...
End If
Enjoy Coding....

regards:
Last edited by jireh; Jan 21st, 2008 at 8:16 pm.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 50
Reputation: lostandfound is an unknown quantity at this point 
Solved Threads: 1
lostandfound's Avatar
lostandfound lostandfound is offline Offline
Junior Poster in Training

Re: Transferring variables across forms in VB6

 
0
  #5
Jan 22nd, 2008
Whoa,whoa,whoa,
Now I'm more confused. Are you describing an example which includes the use of the ADO control. There is a fair bit here that I don't recognise.
I understand that there are several ways to read and write to and from a database. I am currently struggling with the ADO as it seems to be the control of choice for those who know the difference.
Excuse me for my ignorance as I am by no means an expert.
I am happy with the idea of modules (hkdani has set me some homework on class modules which I must attend to).
It still seems to me that if I have opened a connection from my project to an associated database that there should be some way of using that connection across all the forms in that project.(Surely there is a logical way of transferring the properties of the objects involved across the board)
Jireh, please, if there is somrthing I am not grasping with regard to your reply could you explain.
Thanks for the help
Ther are 10 types of people in the world. Those who do understand binary and those who don't!!
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 218
Reputation: hkdani is an unknown quantity at this point 
Solved Threads: 24
hkdani's Avatar
hkdani hkdani is offline Offline
Posting Whiz in Training

Re: Transferring variables across forms in VB6

 
0
  #6
Jan 22nd, 2008
It still seems to me that if I have opened a connection from my project to an associated database that there should be some way of using that connection across all the forms in that project.(Surely there is a logical way of transferring the properties of the objects involved across the board)
Class Modules are the way to go, I would say.

You'll notice that Class Modules have a Data Source and a Data Binding Property.

You write the code to initialize the ADO Database objects and to terminate or close them in the class module.

You can then access this class module from anywhere in your project. Usually, in a form.

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Option Explicit
  2. Dim MyCounter as cmCounter
  3.  
  4.  
  5. Private Sub Form_Load
  6. set MyCounter = new cmCounter
  7. '
  8. '
  9. End sub
  10.  
  11.  
  12. Private Sub Form_Unload
  13. ' Close out your class module
  14. set MyCounter = nothing
  15.  
  16. End sub

Check out the MSDN documentation, if you have the CD's Look for the section Accessing Data Using Visual Basic under the Data Access Guide.

Using Visual Basic/Data Access Guide/Accessing Data Using Visual Basic

Hank
Reply With Quote Quick reply to this message  
Reply

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



Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC