CLOSE Button

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • KMEscherich
    New Member
    • Jun 2007
    • 69

    CLOSE Button

    Access '97

    Hi there. I have the following code:

    If Nz(Me.Author_Na me) = " " then
    Btn_Close.enabl ed = FALSE
    MsgBox "Missing Author Name"
    else
    Btn_Close.enabl ed = TRUE
    End If

    When I test my form out, this code disables the CLOSE button when the control is blank. For some reason, after the control has an entry, the CLOSE button still does not become enabled until after I exit out of the entire record. Is there a way to have it become enabled immediately after the entry in the control?

    Thank you
  • missinglinq
    Recognized Expert Specialist
    • Nov 2006
    • 3533

    #2
    Where do you have this code placed?

    Comment

    • KMEscherich
      New Member
      • Jun 2007
      • 69

      #3
      Originally posted by missinglinq
      Where do you have this code placed?
      Hi there, I have this code at the FORM level and on the OnCurrent event.
      It seems that when I use the navigation arrows and move from one record to another, then it recognizes the change, but just by making an entry into the control, it does not affect the CLOSE button.

      Thank you for assisting me.

      Comment

      • missinglinq
        Recognized Expert Specialist
        • Nov 2006
        • 3533

        #4
        That's what the OnCurrent event does, it fires anytime you move from one record to another! Since you don't want the user to be able to Close the ofrm until the Author_Name has a value in it, do two things.

        Set the form so that on going from one record to another the Focus is set on Author_Name. Do that by adding this line to the code you already have in Form_Current:
        [CODE=vb]Me.Author_Name. SetFocus[/CODE]

        Then use basically the same code you already tried in the Author_Name_Exi t sub, with one additional line, Line 5:

        Cancel = True

        This line automatically returns Focus to the field. Something like this:
        [CODE=vb]Private Sub Author_Name_Exi t(Cancel As Integer)
        If Nz(Me.Author_Na me) = "" Then
        btn_close.Enabl ed = False
        MsgBox "Missing Author Name"
        Cancel = True
        Else
        btn_close.Enabl ed = True
        End If
        End Sub
        [/CODE] Good Luck!

        Linq ;0)>

        Comment

        • KMEscherich
          New Member
          • Jun 2007
          • 69

          #5
          Originally posted by missinglinq
          That's what the OnCurrent event does, it fires anytime you move from one record to another! Since you don't want the user to be able to Close the ofrm until the Author_Name has a value in it, do two things.

          Set the form so that on going from one record to another the Focus is set on Author_Name. Do that by adding this line to the code you already have in Form_Current:
          [CODE=vb]Me.Author_Name. SetFocus[/CODE]

          Then use basically the same code you already tried in the Author_Name_Exi t sub, with one additional line, Line 5:

          Cancel = True

          This line automatically returns Focus to the field. Something like this:
          [CODE=vb]Private Sub Author_Name_Exi t(Cancel As Integer)
          If Nz(Me.Author_Na me) = "" Then
          btn_close.Enabl ed = False
          MsgBox "Missing Author Name"
          Cancel = True
          Else
          btn_close.Enabl ed = True
          End If
          End Sub
          [/CODE] Good Luck!

          Linq ;0)>
          But what if I have 2 required controls on a form? Would I set the SetFocus for each of the required controls in each batch of code? In other words, if I write the code for the AUTHOR NAME and then write the same code for the AUTHOR TITLE. Would I have a SetFocus for each control?

          Thank you.

          Comment

          • KMEscherich
            New Member
            • Jun 2007
            • 69

            #6
            Originally posted by missinglinq
            That's what the OnCurrent event does, it fires anytime you move from one record to another! Since you don't want the user to be able to Close the ofrm until the Author_Name has a value in it, do two things.

            Set the form so that on going from one record to another the Focus is set on Author_Name. Do that by adding this line to the code you already have in Form_Current:
            [CODE=vb]Me.Author_Name. SetFocus[/CODE]

            Then use basically the same code you already tried in the Author_Name_Exi t sub, with one additional line, Line 5:

            Cancel = True

            This line automatically returns Focus to the field. Something like this:
            [CODE=vb]Private Sub Author_Name_Exi t(Cancel As Integer)
            If Nz(Me.Author_Na me) = "" Then
            btn_close.Enabl ed = False
            MsgBox "Missing Author Name"
            Cancel = True
            Else
            btn_close.Enabl ed = True
            End If
            End Sub
            [/CODE] Good Luck!

            Linq ;0)>
            That is WONDERFUL!! Thank you VERY MUCH!! :)

            Comment

            • missinglinq
              Recognized Expert Specialist
              • Nov 2006
              • 3533

              #7
              Glad we could help!

              Linq ;0)>

              Comment

              Working...