Detecting a Sub-Form event from the Main Form 2

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • FelixS
    New Member
    • Feb 2009
    • 16

    Detecting a Sub-Form event from the Main Form 2

    I have developed a way to enter the data from long medical document, using structure: Mainform (subform1,... subfromN). This is reflecting the logical model of data: Document(sectio n1,section2,... sectionN).

    The MainForm has only one control, subfrom, in Detail which displays consecutively section1,...sec tionN. This is done by buttons "Next" and "Previous" located in MainForm's Footer.

    I was quite happy with this design: subforms, which could be of hundreds' did not have class modules, thus saving memory and making design simpler.

    Until data entering person claims, that it would be more comfortable if after one section is filled, the other is coming automatically, without pressing "Next".

    So far I couldn't find a solution for this challenge, i.e. keeping subforms without class modules and fishing up "end of filling the subform" from the MainForm.

    Any hints.
  • ChipR
    Recognized Expert Top Contributor
    • Jul 2008
    • 1289

    #2
    What's the code in your "Next" button? Just to get an idea of what you're doing exactly.

    Comment

    • FelixS
      New Member
      • Feb 2009
      • 16

      #3
      It is very simple there, in class module

      Private Sub NextForm_Click( )
      Call NextPriv(Me.Nam e, 1)
      End Sub


      NextPriv is determining which section is to include in subform.
      For example, there is main form F02 and section forms F02001 - F02005
      Next for F02005 is saving records and close F02. For all other the next Form is
      determined as nextFrm and changes settings by statement

      Forms(pubLFrmNa me).FormSec.Sou rceObject = nextFrm

      This causes main form change the subform contents.

      Comment

      • ChipR
        Recognized Expert Top Contributor
        • Jul 2008
        • 1289

        #4
        In that case, why not have your subform after the last field is updated
        Call NextPriv(Me.Par ent.Name, 1) <- Though I'm not sure what the 1 is for

        Comment

        • FelixS
          New Member
          • Feb 2009
          • 16

          #5
          1. 1 means 1 next, 2 means previous.
          2. The main question is how to do this without class module for subform. In other words, how to fish up the situation of focus on last control in the subform, from the main form. Once more, it is very straightforward to handle this event being in subform and using class module for this subform. However, the solution, being searched is how to do this without class modules for subforms.

          Comment

          • ChipR
            Recognized Expert Top Contributor
            • Jul 2008
            • 1289

            #6
            I don't see any way to get the focus out of the subform without calling a macro or some code.

            Comment

            • FishVal
              Recognized Expert Specialist
              • Jun 2007
              • 2656

              #7
              To the best of my knowledge there is no way to catch subform's components events unless form which is a SourceObject of subform control has module. It could be empty, but it has to exist.
              IMHO, maximum you can do without the modules is continuous polling of subform's controls.

              Regards,
              Fish.

              Comment

              • FelixS
                New Member
                • Feb 2009
                • 16

                #8
                I have found how to do this.

                Comment

                • ChipR
                  Recognized Expert Top Contributor
                  • Jul 2008
                  • 1289

                  #9
                  Would you mind sharing?

                  Comment

                  • FelixS
                    New Member
                    • Feb 2009
                    • 16

                    #10
                    at the moment I have only tested part of code and general Idea.
                    It could be done using
                    Private Sub Form_Timer()
                    <procedure to run every ### milliseconds>
                    End Sub

                    Sub Form_Load()
                    Me.TimerInterva l = 1000
                    End Sub

                    and ActiveControl Property

                    Dim ctlCurrentContr ol As Control
                    Dim strControlName As String
                    Set ctlCurrentContr ol = Screen.ActiveCo ntrol
                    strControlName = ctlCurrentContr ol.Name
                    *************** ***************
                    In fact now I am trying to solve the last outstanding problem in my task:
                    to set focus on the first text box in subform after the form is loaded. The name of text box is stored in variable.
                    So far no any working solution

                    Comment

                    • FishVal
                      Recognized Expert Specialist
                      • Jun 2007
                      • 2656

                      #11
                      Hello, gentlemen.

                      Apparently, it is possible to handle events of subform controls without necessity to create module for subform's source form.
                      A simple example is attached.

                      Regards,
                      Fish.
                      Attached Files

                      Comment

                      • ChipR
                        Recognized Expert Top Contributor
                        • Jul 2008
                        • 1289

                        #12
                        Hi FishVal. Brilliant solution, but a few things I'm puzzled by. If you don't mind my asking,
                        Why is the TimerInterval used? It seems to work fine without it.
                        Why does SbfCtrlHandler return the control (or anything for that matter)? What happens to that when it is returned?
                        Thanks for the new technique,
                        Chip

                        Comment

                        • FishVal
                          Recognized Expert Specialist
                          • Jun 2007
                          • 2656

                          #13
                          Originally posted by ChipR
                          Hi FishVal. Brilliant solution, but a few things I'm puzzled by. If you don't mind my asking,
                          Why is the TimerInterval used? It seems to work fine without it.
                          Hi, Chip.

                          According to OP main form has to detect "end of input" and change subform's SourceObject to a next form thus closing current one. IMHO, even if it works it is not a good idea to close form while its control is waiting for expression to be evaluated.
                          So, SbfCtrlHandler( ) tunes mainform's timer and passes required information to maiform, exits, letting the expression (which is just call of SbfCtrlHandler( )) to be evaluated and then, mainform's timer fires and does all the job.

                          Why does SbfCtrlHandler return the control (or anything for that matter)? What happens to that when it is returned?
                          SbfCtrlHandler( ) returns current value of the control. Since event handler of the control is defined as calculated expression, a value the expression evaluates to will be written to the control.

                          Regards,
                          Fish.

                          Comment

                          • FelixS
                            New Member
                            • Feb 2009
                            • 16

                            #14
                            Hi, FishVal, a very useful code, especially for making guided data entry (e.g. if control1.value is 2 then go to control5).
                            For the current task, to cycle through controls of subform and after last is attended (having been on focus) and "enter" ) trigger the "NEXT subform" procedure, I have found solution and implemented it into codes.
                            As I mentioned, unexpectedly the problem of focus emerged, which still is a mystery to me.

                            I am doing all necessary things with FormSec.setfocu s expression in code.
                            After that, active control is the first control on the subform, this is checked by
                            getActiveContro l() function in immediate panel. But the control itself is not painted with focus, neither is it properly respond to keyboard keystrokes . And only if I click mouse outside the MDB window, aand then inside of MDB window, the focus is coming to control.

                            Comment

                            Working...