• How To Check If Two Fields Are Filled Out (Access 2000)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » How To Check If Two Fields Are Filled Out (Access 2000)

    • This topic has 22 replies, 4 voices, and was last updated 21 years ago.
    Author
    Topic
    #404837

    I have a Payments form that has two check boxes. One for Cheque, and the other for Cash. I need to be able to check and see if one of those boxes is filled in before my form will let you close it or print off a receipt. I still want them to be able to close the form if they have not entered in a record.

    Viewing 1 reply thread
    Author
    Replies
    • #826550

      A check box has the value of -1 if it is checked and 0 if it is not.
      In your case, me.chekbox1 + me.checkbox2 should always have the result -1 before closing the form or before printing.
      Check this in the before update of the form and in the onclick event of the print command button.

      • #826632

        I’m trying that, but I have a mistake somewhere. This is the code I have:

        Private Sub Form_BeforeUpdate(Cancel As Integer)

        If Me.Cheque + Me.Cash -1 Then
        MsgBox “You need to check off whether this payment is made by Cheque, or by Cash.”
        End If

        End Sub

        I put this in the BeforeUpdate property of the form itself. And I put it in to the OnClick event of the Close button. I keep getting an error saying that “Object doesn’t support this property or method. What does this mean? I must be missing something.

        • #826640

          As in your previous post you forget to cancel:

          Private Sub Form_BeforeUpdate(Cancel As Integer)
          If Me.cheque + Me.cash -1 Then
          MsgBox “You need to check off whether this payment is made by Cheque, or by Cash.”
          Cancel = True
          End If
          End Sub

          And if you have a button to print use something like this in the on clickevent of the this button:

          Private Sub cmdPrint_Click()
          If Me.cheque + Me.cash -1 Then
          MsgBox “You need to check off whether this payment is made by Cheque, or by Cash.”
          Exit Sub
          End If
          DoCmd.OpenReport “test”
          End Sub

          • #826644

            Still having trouble. This is what I have on the Click event of the Close button:

            Private Sub ClosePayments_Click()
            On Error GoTo Err_ClosePayments_Click

            If Me.Chq + Me.Cash -1 Then
            MsgBox “You need to check off whether this payment is made by Cheque, or by Cash.”
            Exit Sub
            End If

            If Payment FTotalApplied Then
            MsgBox “The amounts applied do not equal the amount of your payment”
            Payment.SetFocus
            Else
            DoCmd.Close
            End If

            Exit_ClosePayments_Click:
            Exit Sub

            Err_ClosePayments_Click:
            MsgBox Err.Description
            Resume Exit_ClosePayments_Click

            End Sub

            It still gives me the “Object doesn’t support this property or method. Hmmmmmm….

            • #826646

              I don’t know where the error is.
              Are you sure about the names of the checkboxes? In one post you use Me.Cheque and in an other post you use Me.Chq ???
              Attached a little sample db that does what you want.

            • #826647

              I don’t know where the error is.
              Are you sure about the names of the checkboxes? In one post you use Me.Cheque and in an other post you use Me.Chq ???
              Attached a little sample db that does what you want.

          • #826645

            Still having trouble. This is what I have on the Click event of the Close button:

            Private Sub ClosePayments_Click()
            On Error GoTo Err_ClosePayments_Click

            If Me.Chq + Me.Cash -1 Then
            MsgBox “You need to check off whether this payment is made by Cheque, or by Cash.”
            Exit Sub
            End If

            If Payment FTotalApplied Then
            MsgBox “The amounts applied do not equal the amount of your payment”
            Payment.SetFocus
            Else
            DoCmd.Close
            End If

            Exit_ClosePayments_Click:
            Exit Sub

            Err_ClosePayments_Click:
            MsgBox Err.Description
            Resume Exit_ClosePayments_Click

            End Sub

            It still gives me the “Object doesn’t support this property or method. Hmmmmmm….

        • #826641

          As in your previous post you forget to cancel:

          Private Sub Form_BeforeUpdate(Cancel As Integer)
          If Me.cheque + Me.cash -1 Then
          MsgBox “You need to check off whether this payment is made by Cheque, or by Cash.”
          Cancel = True
          End If
          End Sub

          And if you have a button to print use something like this in the on clickevent of the this button:

          Private Sub cmdPrint_Click()
          If Me.cheque + Me.cash -1 Then
          MsgBox “You need to check off whether this payment is made by Cheque, or by Cash.”
          Exit Sub
          End If
          DoCmd.OpenReport “test”
          End Sub

        • #826658

          Instead of Me.Cash you must use Me!Cash, the bang as Charlotte calls, we call it an exclamation mark.
          BTW don’t forget Me.Cheque as well.

          • #826687

            Actually, from within the form, you can use either the bang or dot and Access will recognize what you mean. The difference is that the dot gives you intellisense in the VBE window, while the bang gets compiled at runtime and reduced to a dot. The only places where you are constrained to use one or the other is in queries and when working in code with a recordset.

            The bang in code behind the form will always indicate an object on the form, that is, a control. A dot may refer to the control or to the bound field in the recordset. Just try to keep straight whether you’re referring to the name of the control or the the underlying field.

            • #826693

              Thanks for the explanation Charlotte.

              I’ll take that on board, however I always use the (!) for controls and the (.) for properties.

            • #826694

              Thanks for the explanation Charlotte.

              I’ll take that on board, however I always use the (!) for controls and the (.) for properties.

            • #826936

              I’ve tried both the (.) and the (!), neither work. I don’t know if it’s the fact that these two fields are yes/no. The “name” property on both these fields is Chq, and Cash. I still get the same error as always…”Object doesn’t support this property or method”.

            • #826940

              Have you try my sample from my previous post ? Did it work ?
              If you wish you can post a stripped version of your mdb and I’ll have a look at it.

            • #826944

              I finally figured it out! I kept referring to the label name of both fields and not the field name. Oh, boy, am I loosing my marbles!!! Thanks Francois, Pat & Charlotte.

            • #826945

              I finally figured it out! I kept referring to the label name of both fields and not the field name. Oh, boy, am I loosing my marbles!!! Thanks Francois, Pat & Charlotte.

            • #826941

              Have you try my sample from my previous post ? Did it work ?
              If you wish you can post a stripped version of your mdb and I’ll have a look at it.

            • #826937

              I’ve tried both the (.) and the (!), neither work. I don’t know if it’s the fact that these two fields are yes/no. The “name” property on both these fields is Chq, and Cash. I still get the same error as always…”Object doesn’t support this property or method”.

          • #826688

            Actually, from within the form, you can use either the bang or dot and Access will recognize what you mean. The difference is that the dot gives you intellisense in the VBE window, while the bang gets compiled at runtime and reduced to a dot. The only places where you are constrained to use one or the other is in queries and when working in code with a recordset.

            The bang in code behind the form will always indicate an object on the form, that is, a control. A dot may refer to the control or to the bound field in the recordset. Just try to keep straight whether you’re referring to the name of the control or the the underlying field.

        • #826659

          Instead of Me.Cash you must use Me!Cash, the bang as Charlotte calls, we call it an exclamation mark.
          BTW don’t forget Me.Cheque as well.

      • #826633

        I’m trying that, but I have a mistake somewhere. This is the code I have:

        Private Sub Form_BeforeUpdate(Cancel As Integer)

        If Me.Cheque + Me.Cash -1 Then
        MsgBox “You need to check off whether this payment is made by Cheque, or by Cash.”
        End If

        End Sub

        I put this in the BeforeUpdate property of the form itself. And I put it in to the OnClick event of the Close button. I keep getting an error saying that “Object doesn’t support this property or method. What does this mean? I must be missing something.

    • #826551

      A check box has the value of -1 if it is checked and 0 if it is not.
      In your case, me.chekbox1 + me.checkbox2 should always have the result -1 before closing the form or before printing.
      Check this in the before update of the form and in the onclick event of the print command button.

    Viewing 1 reply thread
    Reply To: Reply #826937 in How To Check If Two Fields Are Filled Out (Access 2000)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information:




    Cancel