Combo Box Conditions

bugman

Registered User.
Local time
Today, 08:32
Joined
Dec 23, 2004
Messages
31
I have a combo box called cmbPaymentMethod it includes several choices such as:

Cash
Check
Visa
MasterCard
PayPal
Charge
No Charge

Also I have a field called txtPaymentAmount.

What I want to do is if the user picks Cash; Check; Visa; MasterCard; or PayPal
and they come to txtPaymentAmount and don't enter an amount then a
MsgBox comes up and lets them know.

I don't want to use the Conditional Formatting button. I want to use code.

Any help would be appreciated.
Tom
 
I would just handle it in the form's BEFORE UPDATE event to make sure that a valid value is there if the combo has one of the types you listed.
 
That is what I want to do, but I don't have the knowledge of how to write the code for that. Could you perhaps offer me a snipit of code.
 
Code:
If Me.cmbPaymentMethod <> "Charge" And Me.cmbPaymentMethod <> "No Charge" Then
    If Len(Me.txtPaymentAmount & "") = 0 Then
         If MsgBox("You have not entered a payment amount." & vbcrlf & _
          "Do you wish to cancel this entry?", vbQuestion + vbYesNo, "Cancel?") = vbYes Then
              Cancel = True
              Me.Undo
         Else
              Cancel = True
              Me.txtPaymentAmount.SetFocus
         End If
    End If
End If

That would go in the FORM's BEFORE UPDATE event.
 
Thats exactly what I wanted, thank you very much Bob
 
Hey Bob,

Just a quick little update on this.
I had to change a few things that you had in the code.
I figured that I would repost my results.

I placed it on the next control's GotFocus.

The numbers represent the PaymentMethodID numbers:

Charge = PaymentMethodID 2
No Charge = PaymentMethodID 5

Private Sub txtPaymentDate_GotFocus()

If Me.cmbPaymentMethod <> 2 And Me.cmbPaymentMethod <> 5 Then

If Me.txtPaymentAmount.Value = 0 Then
MsgBox "You have not entered a payment amount.", vbQuestion + vbOKOnly, "No Payment Entered"
Me.txtPaymentAmount.SetFocus
End If

End If

End Sub

The other thing I had to change was the second "If" statement where you had:

If Len(Me.txtPaymentAmount & "") = 0 Then

For some reason beyond my understanding, it wouldn't work.

Thanks for showing me how to pick out two items out of a combobox.

I know that sounds so newbish, but for whatever reason my mind couldn't come up with it.

Thanks Again,
Tom
 

Users who are viewing this thread

Back
Top Bottom