IIF in FORM - Need help

G

Guest

Is it possible to put IIF function in a text box in form to validate data
entry.

Say Product A & Product B - Loan range between 5000 to 50,000
Product C - Loan range between 20,000 to 100,000

In the validation rule i write

=IIf([product] Like "A*" And Like "B*",[loan] Between 5000 And
50000,IIf([product] Like "C",[loan] Between 20000 And 100000,0))

Thanks
 
G

Guest

Hi Zyus,

Use the Before_Update event procedure for the textbox in question. In the
sample code shown below, the name of the textbox for the loan amount is
"txtLoan", and the name of the textbox for the product is "txtProduct". The
bound fields are named "Loan" and "Product", respectively.

Option Compare Database
Option Explicit

Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo ProcError

Dim strProductCode As String
Dim curLoan As Currency

strProductCode = Left$(Me.Product, 1)
curLoan = Me.loan

Select Case strProductCode
Case "A", "B"
If curLoan < 5000 Or curLoan > 50000 Then
MsgBox "The loan amount is not valid for this product." _
& vbCrLf & "Please enter an amount between $5,000 to
$50,000."
txtLoan.SetFocus
Cancel = True
End If

Case "C"
If curLoan < 20000 Or curLoan > 100000 Then
MsgBox "The loan amount is not valid for this product." _
& vbCrLf & "Please enter an amount between $20,000 to
$100,000."
txtLoan.SetFocus
Cancel = True
End If

Case Else
' Insert appropriate code here
End Select


ExitProc:
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, , _
"Error in Form_BeforeUpdate event procedure..."
Resume ExitProc
End Sub


If my answer has helped you, please answer yes to the question that reads
"Did this post answer the question?" at the bottom of the message thread.

Tom

http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________

:

Is it possible to put IIF function in a text box in form to validate data
entry.

Say Product A & Product B - Loan range between 5000 to 50,000
Product C - Loan range between 20,000 to 100,000

In the validation rule i write

=IIf([product] Like "A*" And Like "B*",[loan] Between 5000 And
50000,IIf([product] Like "C",[loan] Between 20000 And 100000,0))

Thanks
 
G

Guest

Correction:
Use the Before_Update event procedure for the form in question.

Tom
__________________________________________

:

Hi Zyus,

Use the Before_Update event procedure for the textbox in question.....
 
B

BruceM

Regarding "If my answer has helped you, please answer yes to the question
that reads 'Did this post answer the question?' at the bottom of the message
thread," I believe that is an option only with the web-based newsreader. I
don't know if that is what Zyus is using, but if not the request may be
puzzling.
 
G

Guest

Hi Bruce,

I only include that note when I know for sure that the OP used the web-based
newsreader to post the message. This is seen in the web-based newsreader as a
brown circle with a white question mark within it.

I agree that the statement might be confusing to a third party who reads the
reply using a means other than the newsreader. I was simply trying to keep
the request short and simple, without providing an explaination that one will
only see this option using the MS web-based method.

Tom
______________________________________

:

Regarding "If my answer has helped you, please answer yes to the question
that reads 'Did this post answer the question?' at the bottom of the message
thread," I believe that is an option only with the web-based newsreader. I
don't know if that is what Zyus is using, but if not the request may be
puzzling.
 
A

aaron.kempf

man.. just give us more info about what you want

i swear there is a much easier way
 
G

Guest

Aaron,

I have no idea what you are trying to say or why you felt the need to
interject with such a reply....

Tom
______________________________________

:

man.. just give us more info about what you want

i swear there is a much easier way
 

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