Refresh another Form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • NigelBrown
    New Member
    • Oct 2009
    • 34

    #1

    Refresh another Form

    Hi All,

    I am trying to refresh a textbox in form A while in Form B from an OnClick (both forms are open at the same time) - I want to write the below function but do not seem to be able to get this right. I have tried Requery but it does work ?

    need something like

    [code=vb]
    [Forms]![tbl_Ronnie_Mast er]![Textbox].Refresh
    [/code]

    any help/advise will be appreciated
    Thanks
  • ajalwaysus
    Recognized Expert Contributor
    • Jul 2009
    • 266

    #2
    Is one of these a subform in the other, or are they 2 independent forms?

    -AJ

    Comment

    • NigelBrown
      New Member
      • Oct 2009
      • 34

      #3
      Hi AJ,

      No they are two independant forms, the only reason I did not do a subform is becuase I need to see both as continuous. one form changes a calculation after filters are applied, i would like another text box in a another form to pick this up everytime a filter is changed (general idea) - if you have a better way of doing it then please advise

      Comment

      • ajalwaysus
        Recognized Expert Contributor
        • Jul 2009
        • 266

        #4
        Well one thing I would recommend first is to ask if it is possible to make both these forms subforms in a main form, that way, first off you can pull up both forms at the same time and position by calling the main form. Then if you did that, you could refresh Form B from Form A with this code:

        Code:
        Me.Parent.FormB.Requery
        Or else, I am not sure if you can call a requery on an independent form from another. I could very well be wrong and hope someone corrects me if I am.

        -AJ

        Comment

        • Hennepin
          New Member
          • Oct 2009
          • 25

          #5
          This is how I have two forms communicate. I set a form variable to the instance of the open form. I 'use the form's class name instead of form.
          This way VBA returns all controls, public subs and functions
          when typing the dot after the form variable.

          Code:
          Private frmDrawing As Form_Drawings  
          
          Private Sub Form_Open(Cancel As Integer)
              GetLoadedForm "Drawings", frmDrawing
              Me.DJob.DefaultValue = "'" & frmDrawing.DJob & "'"
              Me.DJob.Requery
          End Sub
          
          Private Sub Form_AfterUpdate()
               frmDrawing.Refresh
          End Sub
          
          'mean while In a public module
          
          Function GetLoadedForm(MyFormName, theform As Form) As Boolean
              '  Determines if a form is loaded.
              Const FORM_DESIGN = 0
              Dim i As Integer
              For i = 0 To Forms.count - 1
                  If Forms(i).FormName = MyFormName Then
                      If Forms(i).CurrentView <> FORM_DESIGN Then
                          Set theform = Forms(i)
                          GetLoadedForm = True
                          Exit Function  '  Quit function once form has been found.
                      End If
                  End If
              Next
              GetLoadedForm = False
          End Function

          Comment

          • MMcCarthy
            Recognized Expert MVP
            • Aug 2006
            • 14387

            #6
            I may be wrong but if I am following you I think you need to change the variable scope of frmDrawing from Private to Public.

            Comment

            • Hennepin
              New Member
              • Oct 2009
              • 25

              #7
              Originally posted by msquared
              I may be wrong but if I am following you I think you need to change the variable scope of frmDrawing from Private to Public.
              I realize I did not make myself clear. The form variable and the sub routines are in a form called Drawing_Add. Its scope is only inside the form so it does not need to be public. I could have just defined it by Dim frmDrawing As Form_Drawings.

              Comment

              • MMcCarthy
                Recognized Expert MVP
                • Aug 2006
                • 14387

                #8
                OK I haven't time to check this at the moment but if I remember correctly the refresh only acts on unbound controls whereas you need the requery for bound controls. The refresh is essentially used to clear data from unbound controls and the requery is used to preform calculations on bound (and unbound) controls.

                Having now reread the posts I think I know what your problem is. You're resetting the default value of the control and then trying to requery that value into an existing record. Default value only works on new records. Try passing the value directly into the control rather than resetting the default value.

                Comment

                • NeoPa
                  Recognized Expert Moderator MVP
                  • Oct 2006
                  • 32669

                  #9
                  Actually, I think this is over-cooking the meal. AJ's post #4 is the simple solution. Refresh updates only the data for pre-existing records. A Requery will add new and remove old records from the list. This is required after a filter is applied (as the OP mentions belatedly in post #3).

                  Comment

                  • MMcCarthy
                    Recognized Expert MVP
                    • Aug 2006
                    • 14387

                    #10
                    Originally posted by NeoPa
                    A Requery will add new and remove old records from the list. This is required after a filter is applied (as the OP mentions belatedly in post #3).
                    I should have read them a third time I guess LOL! Thanks Ade.

                    Comment

                    Working...