If...ElseIf...End If with multiple conditions

  • Thread starter Thread starter Dnld
  • Start date Start date
D

Dnld

I am learning VBA for Access. On the form I have Text Box "Cat" and
Combo Box "CatCb". CatCb data source has 6 values including "Dr", "Pt"
and the last value "Undefined". I have class module as follows

Private Sub CatCb_AfterUpdate()
If Nz(Cat.Value) = "" Then
Cat.Value = CatCb
ElseIf Cat.Value <> "Undefined" And CatCb = "Undefined" And
MsgBox("Replace all current Categories with 'Undefined'?", vbYesNo,
"Categories") = vbYes Then
Cat.Value = CatCb
Else
Cat.Value = Cat + " " + CatCb
End If
End Sub

I would think that for ElseIf condition, when 1st or 2nd condition is
not true (that is if Cat.value is already "Undefined" or CatCb is not
"Undefined"), the message box should not even pop up, but it does. I
do not know what I am missing? Any help?
 
Separate the MsgBox() question *inside* the condition to which it applies.

Something like this:

Private Sub CatCb_AfterUpdate()
If Me.Cat <> "Undefined" And Me.CatCb = "Undefined" Then
If MsgBox("Replace all current Categories with 'Undefined'?", _
vbYesNo, "Categories") = vbYes Then
Me.Cat = Me.CatCb
Else
'???
End If
ElseIf Nz(Me.Cat, vbNullString) = vbNullString Then
Me.Cat = Me.CatCb
Else
Me.Cat = Me.Cat & " " & Me.CatCb
End If
End Sub
 
Ciao "Dnld said:
I am learning VBA for Access. On the form I have Text Box "Cat" and
Combo Box "CatCb". CatCb data source has 6 values including "Dr", "Pt"
and the last value "Undefined". I have class module as follows

Excuse, is Italian and I speaks little the English:
Private Sub CatCb_AfterUpdate()
If Nz(Cat.Value) = "" Then
Cat.Value = CatCb


ElseIf isnull(Cat.Value) And isnull(CatCb) And
 
Back
Top