combo box column compared

R

redFred

I swear that I've done this, but maybe not!

I wish to compare a combo box selection's column(4) to an entry control.

The combo box is bound and returns 7 columns (I know about 0 column
counter). I am only concerned here with column 4 as that is an amount of an
invoice.

User enters into a different control a receipt amount.

I wish to test the entered receipt amount against the selected column amount.

Example:

if me.[txtReceipt] > me.[cboInvoice].column(4) ... do something.

How do I do this? I have no clue.

Thanks.
 
B

Beetle

It depends. If you don't want the value in txtReceipt to be committed to
the table unless it meets certain criteria, then you would use the
Before Update event of txtReceipt. For example;

Private Sub txtReceipt_BeforeUpate (Cancel As Integer)

If Me.txtReceipt > Me.cboInvoice.Column(4) Then
MsgBox "Value entered is too high"
Cancel = True
End If

End Sub


On the other hand, if you want to let the value be committed to the table
and just compare it, then use the After Update event of txtReceipt i.e.;

Private Sub txtReceipt_AfterUpdate

If Me.txtReceipt > Me.cboInvoice.Column(4) Then
do something...
Else
do something else
or do nothing
End If

End Sub
 
R

redFred

Thanks Beetle. You have confirmed that the following should work. I thought
it was at one time -- it does not now. Allows any amount to be entered.

Code:

Private Sub txtAmount_BeforeUpdate(Cancel As Integer)
Dim msgTooMuch, style, title, response As String
title = "Invalid Request!"
style = vbOKOnly
msgTooMuch = "Amount exceeds invoice price."

'checks for amount more than invoice
If Me.txtAmount > Me.cboInvNum.Column(4) Then
response = MsgBox(msgTooMuch, style, title)
Me.txtAmount.SetFocus
Cancel = True
Me.txtAmount.Undo
End If

End Sub

I thought this was working, but maybe I changed something without realizing.
What could make it not make the comparison?

I ran debug and the comparison is skipped...even when [txtAmount] exceeds
[cboInvNum].column(4).

Any ideas?

--
redFred






Beetle said:
It depends. If you don't want the value in txtReceipt to be committed to
the table unless it meets certain criteria, then you would use the
Before Update event of txtReceipt. For example;

Private Sub txtReceipt_BeforeUpate (Cancel As Integer)

If Me.txtReceipt > Me.cboInvoice.Column(4) Then
MsgBox "Value entered is too high"
Cancel = True
End If

End Sub


On the other hand, if you want to let the value be committed to the table
and just compare it, then use the After Update event of txtReceipt i.e.;

Private Sub txtReceipt_AfterUpdate

If Me.txtReceipt > Me.cboInvoice.Column(4) Then
do something...
Else
do something else
or do nothing
End If

End Sub

--
_________

Sean Bailey


redFred said:
I swear that I've done this, but maybe not!

I wish to compare a combo box selection's column(4) to an entry control.

The combo box is bound and returns 7 columns (I know about 0 column
counter). I am only concerned here with column 4 as that is an amount of an
invoice.

User enters into a different control a receipt amount.

I wish to test the entered receipt amount against the selected column amount.

Example:

if me.[txtReceipt] > me.[cboInvoice].column(4) ... do something.

How do I do this? I have no clue.

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