Hello,
I have been trying with no success to transfer a recordset from one form to another.
I have declared in Form1 that

Public myRS As ADODB.Recordset

All works lovely in Form1
In Form2 when I use

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.:confused:

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

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

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.

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:

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:-/

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.

Option Explicit
Dim MyCounter as cmCounter


Private Sub Form_Load
set MyCounter = new cmCounter
'
'
End sub


Private Sub Form_Unload
' Close out your class module
set MyCounter = nothing

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

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.