on current event only working going forward

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SeadooRider
    New Member
    • Jan 2013
    • 48

    on current event only working going forward

    I have textboxes that become enabled based on a listbox so users can enter data. However, I'd like them to stay not enabled if no text is inputted. The code I have in the "current" even, makse this happen but only when I move forward through the records. If I move back, the textboxes enabled from other records remain enabled, even if there is no text in them.

    Ex. rec 1 has data in txtbox 1
    rec 2 has data in txtbox 3

    When you move from rec 1 to rec 2 txtbox 1 becomes no enabled since there is no data in it. All good, but when I go from rec 2 to rec 1, txtbox 3 remains enabled when it should be not enabled since there is no text in that box for rec 1.

    See attached code:
    Attached Files
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    As a rule of thumb, I do not download attachments from strangers. Please post the code in the thread instead. Surround the code in code tags when doing so.

    This sounds like an Access question, if so, you are in the wrong forum. Let me know and I'll move it to the Access forum.

    Comment

    • SeadooRider
      New Member
      • Jan 2013
      • 48

      #3
      yes, it is an access question. sorry

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32633

        #4
        Originally posted by Rabbit
        Rabbit:
        Please post the code in the thread instead. Surround the code in code tags when doing so.
        @SeadooRider.
        Please pay attention to what's posted - especially when posted by a moderator (They have "Mod" in green below any avatar over on the left). To help you we need to see your code.

        As for your question, you need to ensure the code that is run does both of :
        1. Sets the visibility to True when it should be visible.
        2. Sets the visibility to False when it should not be visible.

        Otherwise you'll see exactly what you report. Once any record sets the visibility to True it will stay True for ever.
        Last edited by NeoPa; Jan 15 '13, 04:46 PM. Reason: Added help for question.

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32633

          #5
          Originally posted by Rabbit
          Rabbit:
          Please post the code in the thread instead. Surround the code in code tags when doing so.
          @SeadooRider.
          Please pay attention to what's posted - especially when posted by a moderator (They have "Mod" in green below any avatar over on the left). To help you we need to see your code.

          Does anyone else ever get that feeling of déja vu?

          Comment

          • SeadooRider
            New Member
            • Jan 2013
            • 48

            #6
            Ok, so I have a listbox with OfcHW and OfcSW among others in it.
            With the code below, as I click an item, the corresponding txtbox becomes enabled.

            Code:
            Private Sub Mylist_AfterUpdate()
                  Dim i As Long
                  For i = 0 To MyList.ListCount - 1
                      If MyList.Selected(0) Then
                        txtOfcHW.Enabled = True
                      Else
                        txtOfcHW.Enabled = False
                    
                      If MyList.Selected(1) Then
                        txtOfcSW.Enabled = True
                      Else
                        txtOfcSW.Enabled = False
                      End If
                      End If
                  Next i
                  
            End Sub
            And on current, I have the following code which should check to see if the txtboxes have data. If not they are not supposed to be enabled.

            Code:
            Private Sub Form_Current()
              If txtOfcHW <> "" Then
               txtOfcHW.Enabled = True
              Else
               txtOfcHW.Enabled = False
            
              If txtOfcSW <> "" Then
               txtOfcSW.Enabled = True
              Else
               txtOfcSW.Enabled = False
            End If
            End If
            End Sub
            However, it seems to be remembering what was selected for the 2nd record because the 2nd txtbox remains enabled when returning to the 1st record even when there is no txt in the box in the 1st record.

            I'm sure that is clear as mud but I'm sure it has an easy fix I'm just not putting together or I'm conflicting what I want to form to do.

            Thx.
            Last edited by Rabbit; Jan 15 '13, 08:16 PM. Reason: Please use code tags when posting code.

            Comment

            • Rabbit
              Recognized Expert MVP
              • Jan 2007
              • 12517

              #7
              Are you sure it's a blank string and not a null? They sometimes look the same but are not.

              Comment

              • SeadooRider
                New Member
                • Jan 2013
                • 48

                #8
                I changed it to read:

                Code:
                Private Sub Form_Current()
                    If Not IsNull([txtOfcHW]) Then
                            txtOfcHW.Enabled = True
                        Else
                            txtOfcHW.Enabled = False
                            If Not IsNull([txtOfcSW]) Then
                                    txtOfcSW.Enabled = True
                                Else
                                    txtOfcSW.Enabled = False
                            End If
                    End If
                End Sub
                and it does the same thing. seems to disable fields without text in them if I'm advancing, but not when I'm going to previous records.

                I also tried putting this code into the next and previous command buttons with no success there either.
                Last edited by zmbd; Jan 16 '13, 03:43 AM. Reason: [Rabbit{Please use code tags when posting code.}][Z{Reformated the code to show the nesting better}]

                Comment

                • Rabbit
                  Recognized Expert MVP
                  • Jan 2007
                  • 12517

                  #9
                  Please use code tags when posting code.

                  That is odd, you may have to zip and attach the database so we can examine it closer.

                  Comment

                  • NeoPa
                    Recognized Expert Moderator MVP
                    • Oct 2006
                    • 32633

                    #10
                    Even though your code is not indented to indicate it, your second If statement (Line #7 from post #8) is included within the first (which is why it will not work reliably when going backwards, but only in certain restricted circumstances).

                    Try instead :
                    Code:
                    Private Sub Form_Current()
                      With Me.txtOfcHW
                        .Enabled = (.Value > "")
                      End With
                      With Me.txtOfcSW
                        .Enabled = (.Value > "")
                      End With
                    End Sub
                    PS. Checking a control's value is <> "" or even > "" works for Null results as well as ZLS ("") ones.

                    Comment

                    • SeadooRider
                      New Member
                      • Jan 2013
                      • 48

                      #11
                      I'm not sure I understand how it would be written if they aren't supposed to be separate If statements.

                      Comment

                      • Seth Schrock
                        Recognized Expert Specialist
                        • Dec 2010
                        • 2965

                        #12
                        They should be separate IF statements, but the way that you have your code, the second IF statement is inside of the first. So you would need to add an End If in line 8 of the first block of code and line 6 of the second block and then remove the End If in line 14 of the first block and line 12 of the second block to make them separate IF statements.

                        Comment

                        • SeadooRider
                          New Member
                          • Jan 2013
                          • 48

                          #13
                          Thanks Seth, works perfectly. On to the next question.
                          Last edited by NeoPa; Jan 16 '13, 03:23 AM. Reason: Removed new question. Feel free to post a link in here to the new one when posted if you think that will help.

                          Comment

                          • Seth Schrock
                            Recognized Expert Specialist
                            • Dec 2010
                            • 2965

                            #14
                            As that is a different question than was originally asked, it must be asked in a different thread. Also, when you do repost it, please use code tags. The button just above where you type that says <CODE/> adds the code tags for you. It is incredibly hard to read code that doesn't have these included to format it.

                            Comment

                            • SeadooRider
                              New Member
                              • Jan 2013
                              • 48

                              #15
                              Thanks, will do. sorry, learning my way around this site. Lots of great help. thanks again.

                              Comment

                              Working...