• Using ‘yes/no’ with forumulas (2000)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Using ‘yes/no’ with forumulas (2000)

    Author
    Topic
    #389421

    Back again. I’m trying to code a form so that it will look to see if the Account is Tax Exempt or not and the apply tax accordingly. Whenever I use If/than statements with yes/no controls I have no luck. This is what I wrote.

    If me.TaxeExpemptStatus.value = “No” then
    [SalesTax] = [LaborCost] * .06
    Else: [SalesTax] = 0
    End if

    And, I’ve tried:

    If me.TaxeExpemptStatus.value = “No” then
    [SalesTax] = [LaborCost] * .06
    Else if me.TaxExepmtStatus.value = “Yes” then
    [SalesTax] = 0
    End if

    I’ve tried taking out the word “value” as well as putting in -1 for no and 1 for yes and still the code doesn’t run.

    Leesha

    Viewing 1 reply thread
    Author
    Replies
    • #687571

      Yes and No are constants, not strings. Take the quotes out from around them and you should be OK.

      If me.TaxeExpemptStatus.value = No then

    • #687572

      In the first place, check for spelling errors again. In your post, you have TaxExPemptStatus and TaxExePmptStatus.

      In the second place, a Yes/No field has values True and False (without quotes)

      Assuming that the control is named TaxExemptStatus, the code could be

      If Me.TaxExemptStatus = True Then
      Me.SalesTax = 0
      Else
      Me.SalesTax = Me.LaborCost * .06
      End If

      • #687573

        Hi,

        There weren’t any spelling errors in the code. I just typed in the various things I’d tried vs cut and paste since I’d tried various versions. I’m pretty sure its related to the quotes as Charolotte just pointed out.

        Thanks to both of you!
        Leesha

        • #687575

          Also Hans solution could be changed from:
          If Me.TaxExemptStatus = True Then

          to:
          If Me.TaxExemptStatus Then

          This assumes that you are indeed testing for True.

          • #687583

            I kept the yes/no and took away the quotes and that corrected the issue. Another learning experience.

            Thanks to all three of you!

            Leesha

            • #687765

              The use of yes and no doesn’t raise an error message only because you don’t have Option Explicit in your modules; you should replace them by True and False.

            • #687773

              Morning Hans!

              Missed ya yesterday, but Pat and Charlotte took care of me.

              I don’t have a problem changing the yes/no to true/false but am just wondering why yes/no is even given as an option when setting up a table. Its my need to understand kicking in again!

              Leesha

            • #687777

              In a table and in a query, you can use Yes/No or True/False as you please. This is the interface for “everyone”, it should be as user-friendly as possible.
              In Visual Basic, you must use True/False. Code windows are just for programmers; the end user should never see them.

            • #687818

              OK, that makes sense to me. Thanks for the explanation!!

              Alicia

          • #687576

            That isn’t a good idea, Pat. It is recommended against in knowledgebase articles, and I have seen it cause problems.

            A checkbox control needs to be evaulated either with the full expression Me.Checkbox=True or by forcing an evaulation by enclosing the reference in parens (Me.Checkbox). Not doing so is one of the many causes of databases closing but the Access process remaining open.,

            • #687578

              Whoa, I have noted that one. Why on earth don’t they fix it, especially if they allow it?

            • #687586

              You’d have to ask Microsoft that question. I suspect it’s more a VBA issue than a pure Access issue though, since there seems to be a memory leakage associated with that kind of code statement.

    Viewing 1 reply thread
    Reply To: Reply #687583 in Using ‘yes/no’ with forumulas (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