ssalem, what you want to do is define your function. It's currently just a fake sub.
Subs execute, functions return.
So you could do something like this to make sure your object is passed and returned:'
Private Function Pieces1(rs as DAO.Recordset) as DAO.Recordset
The first section, "(rs as DAO.Recordset)" defines what the function receives. This can be done with subs as well. The second part is unique to functions - it defines what the function is, what it returns. It's how the compiler knows that when integer "X = CalculateIntegerFromCoffee(coffee)" that CalculateIntegerFromCoffee will return an Integer Type object. It also turns the function into a variable within itself.
For example, a very simple setter/getter from a data structure:
Code:
Public Sub SetName(strName as String)
name = strName
End Sub
Public Function GetName() as String
GetName = name
End Function
so what you might want to do is something like this
Code:
Private Sub Pieces1(rs as DAO.Recordset)
Mcount2 = Mcount2 + 1
Do Until rs10!fld1 = "No. of Pieces"
rs10.MoveNext
mcount = mcount + 1
Loop
rs10.Move Mcount2
mcount = mcount + Mcount2
End Sub
I can't tell exactly what you're doing with mcount and mcount2 though.
On the topic of public/private function/sub
Most things should be private. Only make it public if you would want something other than itself to be able to access it. For instance the setter/getter concept is a result of the idea that classes should know about themselves, and ask about eachother. You shouldn't call the properties of another class directly, but by asking the class for it - same with changing it . This ensures that the data is received as intended.
Subs are used when nothing is returned, or expected returned.
so whereever this is being called you would do something like "Pieces1 rs" to call it and pass it the recordset (assuming your recordset exists before the call and is called rs, and no return data is expected)