Results 1 to 12 of 12
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Canada
    Posts
    284
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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.

  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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.
    Francois

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Canada
    Posts
    284
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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.

  4. #4
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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
    Francois

  5. #5
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Canada
    Posts
    284
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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....

  6. #6
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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.
    Attached Files Attached Files
    Francois

  7. #7
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

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

    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.

  8. #8
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

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

    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.
    Charlotte

  9. #9
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

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

    Thanks for the explanation Charlotte.

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

  10. #10
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Canada
    Posts
    284
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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".

  11. #11
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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.
    Francois

  12. #12
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Canada
    Posts
    284
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •