Hiding object in a split form?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dpot
    New Member
    • Oct 2014
    • 30

    Hiding object in a split form?

    At the top of the form I have "Report ID" which is the primary ID number and "Linked ID #" which is the ID number of the '2nd page' if there is a second page. This form is a split form so the user can click on any piece of data in the table at the bottom. I have 2 labels at the top of the page, one says "Page 1" one says "Page 2" this is there if there are more than 1 page. I'm trying to get it so if the Report ID Value is less than the Linked ID Value then "Page 1" would be visible and vice versa for "Page 2". For the 1st page the Report ID will always be less than the Linked ID # and the 2nd page will always be the other way around. The code is:

    Code:
    If Me.Report_ID.Value < Me.LinkID.Value Then
    Me.Page1.Visible = True
    End If
    If Me.Report_ID > Me.LinkID.Value Then
    Me.Page2.Visible = True
    End If
    Since this form doesn't open or close or reset I'm not quite sure how to execute this idea. I have pasted it in after update, on focus, data change, data set change of the form as well as the report Id object. I can not for the life of me figure it out. I'm still learning VBA so any input to point me in the right direction would be greatly appreciated.
  • jforbes
    Recognized Expert Top Contributor
    • Aug 2014
    • 1107

    #2
    The Form OnCurrent Event is usually the place to put code that that you want to be executed when the Current Record changes.

    Comment

    • Dpot
      New Member
      • Oct 2014
      • 30

      #3
      I tried that :/ Still nothing.

      Comment

      • Dpot
        New Member
        • Oct 2014
        • 30

        #4
        Page 1 shows, but once I change records nothing happens. It doesn't switch to Page 2.

        Comment

        • jforbes
          Recognized Expert Top Contributor
          • Aug 2014
          • 1107

          #5
          Is your code executing and just not doing what you want? Or is it not executing when you expect it to?

          I am a little confused as to what you and the code are attempting to do.

          Comment

          • jforbes
            Recognized Expert Top Contributor
            • Aug 2014
            • 1107

            #6
            You might need to drop a break point into your code and see what values you are getting. It does look a bit strange that the if statement for Page1 and Page2 are the same.

            Comment

            • Dpot
              New Member
              • Oct 2014
              • 30

              #7
              If the value within report id is less than the value within linked id then show the label for page 1

              If the value within report id is greater than the value within linked id then show label for page 2.

              This is what I'm trying to do. Code doesn't execute at all... the form opens and the label that says page 1 is visible but that never changes if I go to the next id # (which is linked to the original Id#)
              Last edited by Dpot; Dec 2 '14, 07:23 PM. Reason: typo

              Comment

              • jforbes
                Recognized Expert Top Contributor
                • Aug 2014
                • 1107

                #8
                I'm confused as to why the code doesn't execute. Maybe try this:
                1. From the Form Design, right-click on the background of your Form. This should get "Form" to show up at the top of your Properties Window.
                2. In the Properties Window, select the Event Tab, then cliek on the "..." for the "On Current" Property and select Code Builder.
                3. Then copy-paste the code below in for your Form_Current. (Be sure to save of a copy of the current code, if any, so that you can revert if need be):

                Code:
                Private Sub Form_Current()
                    Dim bVisible As Boolean
                    bVisible = (Me.Report_ID.Value < Me.LinkID.Value)
                    Me.Page1.Visible = bVisible
                    Me.Page2.Visible = (Not bVisible)
                End Sub
                If you need to, you can put a break in here to see the values of Report_ID and LinkID.

                I think you are in a situation where you need to set the visible property on all your controls since you are toggling back and forth.

                If you get things setup like this, your code should fire every time the record changes.

                Comment

                • jforbes
                  Recognized Expert Top Contributor
                  • Aug 2014
                  • 1107

                  #9
                  It just hit me! I should have known better as I've ran into this before. You are using a Split Form which is in a way is two separate instances of the Form running in the same container. I apologize for not catching this earlier as it's this strangeness that brought me to Bytes in the first place: http://bytes.com/topic/access/answer...-a#post3778277

                  You might want to try this:
                  Code:
                  Public Sub callFormCurrent()
                      Call Form_Current
                  End Sub
                  Private Sub Form_Current()
                      If Me.CurrentView = 2 Then
                          Forms(Me.Name).callFormCurrent
                      Else
                          Dim bVisible As Boolean
                          bVisible = (Me.Report_ID.Value < Me.LinkID.Value)
                          Me.Page1.Visible = bVisible
                          Me.Page2.Visible = (Not bVisible)
                      End If
                   End Sub
                  When you change records, the Form will determine if it is on the Datasheet (SplitForm) instance or the SingleForm instance. If it is on the SingleForm instance it will just execute the code. If it is on the Datasheet instance, it will call the SingleForm's version of Form_Current.

                  Comment

                  • Dpot
                    New Member
                    • Oct 2014
                    • 30

                    #10
                    Still Nothing. I'll try playing around with the code you provided and hopefully something happens, if not I'll just have to make a whole other form to use as my page 2 but I was hoping to avoid that all together. Thank you so much!

                    Comment

                    Working...