Giving myself a "If, end if" headache

  • Thread starter Thread starter Cheeshead
  • Start date Start date
C

Cheeshead

Guest
OK I'm trying to figure this out, and I giving myself a migrane. i have it partially complete but can't get it 100%....Let me see if I can explain.

Fields - TaxID, Country
Buttons A(command33), B(command34), C(command35) (the buttons are for printing reports)
Criteria: (here's where the fun starts)

1. When Country = USA or Canada, button A is disabled
2. When countrs does not = USA or Canada, button B and C are disabled
3. When TaxID = any value, button B is disabled
4. When TaxID = no value, button C is disabled
---Now this I can get, but when Country does not = USA or Canada,
and TaxID = no value, button B enables itself, when I need it disabled.

Here's my code:
If Me.Sold_to_Country = ("USA") Then
Command33.Enabled = False
Command34.Enabled = True
Command35.Enabled = True
Else: Command33.Enabled = True
Command34.Enabled = False
Command35.Enabled = False
If Me.Sold_to_Country = ("Canada") Then
Command33.Enabled = False
Command34.Enabled = True
Command35.Enabled = True
Else: Command33.Enabled = True
Command34.Enabled = False
Command35.Enabled = False
End If
End If
If Not IsNull(Me.Tax_ID) Then
Command34.Enabled = False
Else: Command34.Enabled = True
End If
--

Any help would be greatly appreciated.
 
Last edited:
Hi

Does the tax value condition over-ride the country conditions? If condition 1 is met and B & C are enabled, does the tax value condition over-ride the country settings for B or C?

Also, if condition 2 is met, then B & C are already disabled so why is the tax value test required if condition 2 is met and both buttons are already disabled? Is it because when you say disable B, that you want C enabled at the same time? And vice versa (under condition 2) if you disable C, do you want B enabled at the same time? I don't think this is the case but I thought I would ask anyway...

My immediate thoughts are two-fold : if B & C are permanently disabled because condition 2 is met (and not modified by the tax test), then nest the tax value conditions inside the country code text. Secondly, use the Nz function and test for zero rather than null.

One way (using your logic) :

Code:
If Me.Sold_to_Country = ("USA") Or Me.Sold_to_Country = ("Canada") Then
 Command33.Enabled = False
 If Nz(Me.Tax_ID) = 0 Then
  Command34.Enabled = True
  Command35.Enabled = False
 Else
  Command35.Enabled = True
  Command34.Enabled = False
 End If
Else
 Command33.Enabled = True
 Command34.Enabled = False
 Command35.Enabled = False
End If

But if the tax condition over-rides the country test, then try something like this instead :

Code:
If Me.Sold_to_Country = ("USA") Or Me.Sold_to_Country = ("Canada") Then
 Command33.Enabled = False
 Command34.Enabled = True
 Command35.Enabled = True
Else
 Command33.Enabled = True
 Command34.Enabled = False
 Command35.Enabled = False
End If
If Nz(Me.Tax_ID) = 0 Then
 Command35.Enabled = False
Else
 Command34.Enabled = False
End If

But, if when you say disable 34 you mean disable 34 but enable 35 at the same time (and the tax condition absolutely over-rides the country condition), then change the last piece of the code to this :

Code:
If Nz(Me.Tax_ID) = 0 Then
 Command34.Enabled = True
 Command35.Enabled = False
Else
 Command34.Enabled = False
 Command35.Enabled = True
End If

If I haven't explored the options (or understood the problem) correctly, then I recommend you draw a with the country code on one axis and the tax conditions on the other, and work out which buttons you want enabled and disabled for each quadrant.

Please note I haven't tested the code - I merely used the wording and syntax you provided and modified it for the Nz and Or functions.

HTH, Andrew :)
 
Last edited:

Users who are viewing this thread

Back
Top Bottom