logic tree expression problem

And here it is in 'code':

Code:
Private Sub Main()
    If Test1() Then
        If Test2() Then
            If Test3() Then SubTest4()
        Else
            SubTest4()
        End If
    End If
    Do9()
End Sub

Private Sub SubTest4()
    If Test4() Then
        If Test5() Then SubTest6()
    Else
        SubTest6()
    End If
End Sub

Private Sub SubTest6()
    If Test6() Then
        If Test7() Then SubTest6() 'recursive sub - CAREFUL!!
    Else
        Do8()
    End If
End Sub
 
Hehe, good point about the 9's, hadn't thought about it that way :)

And yea, doing the diagram really helped me understand the layout for nesting/what I can copypaste/what i can put in a sub without going near any Goto's :)

Ohh, i'd not seen the byref thing before, I have 6 recordsets tho :/ might just nest it up with some copypaste, doesn't actually look too bad now we've broken it down :) (and i'm not at all confident trying to pass the recordsets about, i've only just started using them in this project)
edit: actually the 3 subs would have one recordset each, 9 would have its own at the end and i'd just have to pass one or two about, simples :)
thank you so much :)

By saying it's name :o
ah yes, embarrassed indeed, sorry, all this nesting has un-object-oriented my thinking this evening!
 
Passing objects (and variables sometimes) byref is an immensely useful thing to know how to do and not complicated at all. You can pass a control from a form's module to a public function in a public module for example and manipulate it there in a way that can be reused across all forms.
It's really easy :)
 
I've used functions to pass form fields to queries etc and do a bit of formatting etc on the way, didn't really realise what it was i was doing at the time!

will the cursors on the recordsets stay where they are when they are passed to the subs? (i'm using Loop - MoveNext to progress down a list)
 
yes, the recordset won't change in the slightest as it gets passed around (except when your code changes it).

Code:
Private Sub DemoByRef1()
    Dim rs1 As DAO.Recordset
    Set rs1 = CurrentDb.OpenRecordset("Table1", dbOpenDynaset)
    rs1.MoveFirst
    Do While Not rs1.EOF
        DemoByRef2 rs1
    Loop
    rs1.Close
End Sub

Private Sub DemoByRef2(ByRef rs As DAO.Recordset)
    With rs
        .Edit
        !Field1 = "demo"
        .Update
        .MoveNext
    End With
End Sub
 
Last edited:

Users who are viewing this thread

Back
Top Bottom