If Then Else Hell

I

Ian

I keep getting erroneous error messages and the allowedits property set
wrong. What I need to do is evaluate a combobox (contract/combo14) for 4
things prior to letting it be updated:
I want to be able to edit it if:
It is the next record (null)
Is is an active contract (sum of active status =-1)
I want it locked if:
there are records associated with that contract (count services <>0)
or it is an inactive contract. I've tried a variety of If then and thought
this might work and set the GotFocus() for Combo14 to Allowedits = True

Private Sub Combo14_mousedown(Button As Integer, Shift As Integer, X As
Single, Y As Single)
If (IsNull(Combo14) Or (DSum("active", "LU_contracttypes",
"contracttype=forms.frm_main.frm_contracts.form.combo14") = -1)) Then
Me.AllowEdits = True
Else
If DCount("render", "services",
"contractID=forms.frm_main.frm_contracts.form.contractid") <> 0 Then
Me.AllowEdits = False
MsgBox "Contract has services assinged and cannot be altered. Delete
Services then alter Contract", 16
Else
Me.AllowEdits = False
MsgBox "Inactive Contract: Cannot be altered", 16
End If
End If
End Sub
 
K

Keith Wilby

I haven't read your code in detail but try the format:

If condition1 Then
Do stuff
ElseIf condtion2 Then
Do other stuff
ElseIf condtion3 Then
Do something different
Else
Do more stuff
End If

I'm not sure the mouse down even is the one to use either, how about Before
Update which you can cancel?

Keith.
www.keithwilby.com
 
I

Ian

Hey Keith -- not sure if you're getting emails from this thread but I've run
into a problem with the logic. I need it to stay in mouse down and it works
for the most part but the logic of how to structure this is killing me.
Thought about trying to build a goto statment but 1. i don't know how and 2.
online people hate it.

Here's the problem: the contract field can be null, active/inactive, have
services assigned to it/not. If it is null, active and no services it can be
edited otherwise not. But an inactive contract can have services and I don't
want user to get multiple error messages. Here's what I thought (just logic
wise -- haven't put in actual criteria)

On mouse_down
If IsNull Then
AllowEdits
GoTo EndSub (not sure how to code this logic)
ElseIf (Inactive) Then
GoTo Inactive message and msgbox "inactive" and allowedit = false
ElseIf (Services assigned) Then
GoTo Services message and msgbox "services" and allowedits = false
Else
Allowedits = True

Does this make sense and how do I code the GoTo statments?

Thanks Ian.
 
S

SteveS

PMFJI,

Here's the problem: the contract field can be null, active/inactive, have
services assigned to it/not. If it is null, active and no services it can be
edited otherwise not. But an inactive contract can have services and I don't
want user to get multiple error messages. Here's what I thought (just logic
wise -- haven't put in actual criteria)


This is very confusing. It sounds like you are talking about the combo box,
but how can the combo box be active or inactive AND have services assigned to
it or not?

Are you talking about a contract?

If a contract can be active or inactive AND have services assigned to it or
not, when looking at the form, what are tne control names that will tell you:

if the contract is active or inactive?

if the contract has services assigned or not?


So you want to be able to edit combo14 if

combo14 is null AND
Active is TRUE AND
ServicesAssigned = 0

otherwise

don't allow combo14 to be edited


Is this right?
 
I

Ian

OK -- got it --- turned off the editing and made the statements
If combo14 is null OR
( Active is TRUE AND
ServicesAssigned = 0).
then allowedits.

after update turn off

Worked like a charm. thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top