If Then Statement

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm struggling with an if, then statement. I have a combo box [status] on a
form. When the user selects "complete" a message box reminds the user to go
to another combo box [savings] and select the appropriate answer. That
second box is not required (and thus is null) until the status box is marked
complete. I need to force the user to select an answer from the savings
combo box if status is complete. I have not had enough caffeine so I can't
spot my problem, though I'm sure it is not a difficult line of code, and I
only know enough VB to be dangerous :)

The logic (or illogic :) I'm using is ... if status = complete, then
savings cannot be null.

The code below returns a function call error, that the left hand side must
return a variant or object.
If (Me.Status) = complete Then IsNull(Me.Savings / Avoidance) = False
End If
 
Hi Tedd, hows this sound:

on form close/exit event,

If status = complete then
if savings is null then
'cancel exit operation
'prompt user/ msg box to select an option from savings
end if
end if

alternativley you can use case select instead of if statements?

Hope this helps!
Sam
 
Thanks Sam,
That's the other direction I was going, in either case the check was to be
before update, I think I just made it too complicated with one statement
rather than two.
 
well i realize my solution is probably a simplistic one, as im still
learning, but i hope i could help :)
Sam
 
Tedd N said:
I'm struggling with an if, then statement. I have a combo box
[status] on a form. When the user selects "complete" a message box
reminds the user to go to another combo box [savings] and select the
appropriate answer. That second box is not required (and thus is
null) until the status box is marked complete. I need to force the
user to select an answer from the savings combo box if status is
complete. I have not had enough caffeine so I can't spot my problem,
though I'm sure it is not a difficult line of code, and I only know
enough VB to be dangerous :)

The logic (or illogic :) I'm using is ... if status = complete, then
savings cannot be null.

The code below returns a function call error, that the left hand side
must return a variant or object.
If (Me.Status) = complete Then IsNull(Me.Savings / Avoidance) = False
End If

This code would be inthe form's BeforeUpdate event, I take it? That's
where it makes the most sense to me. It might look something like this:

'----- start of code -----
Private Sub Form_BeforeUpdate(Cancel As Integer)

If Me.Status = "complete" Then
If IsNull(Me![Savings / Avoidance]) Then
Cancel = True ' cancel update
MsgBox _
"You must fill in the the savings.", _
vbOkOnly,
"Required Field"
Me![Savings / Avoidance].SetFocus
End If
End If

End Sub
'----- end of code -----

I've assumed that "Savings / Avoidance" is the name of a single control
on your form, and not intended to represent the division of two fields.
If I'm right about that, be aware that it's really not a good idea to
use spaces and arithmetic operators, or any nonstandard characters, in
field or control names.
 
Back
Top