IF ELSE STATEMENT

  • Thread starter Thread starter JB
  • Start date Start date
J

JB

I have a query regarding Access programming. I do not
know whether it is a simple or a difficult query.

I have a form which uses a text box by the name 'rate'.
There is combo box 'Customer ID' and 'Description' text
box. I want the rate box to display the value after
evaluating the Customer ID box and the description box.
If I write the word 'nylon' in the description box, it
should take one value and if I write the word 'zinc' in
the description box, it should take the value from the
table. The code that I have written in the afterevent
procedure of the description box is as under:

Private Sub Description_AfterUpdate()

If Forms![Challans]![Subform]!Description = "*nylon*"
Then
Me!Rate = "1.9"
ElseIf Forms![Challans]![Subform]!Description
= "*zinc*" Then
Me!Rate = DLookup
("[Rate]", "Customers", "[CustomerID]=" _
& Forms![Challans]!CustomerID)
Else
Me!Rate = ""
End If

End Sub

The problem is that it just does not catch nylon or zinc.
Like if I write "1 nylon plate of Crest" in the
description column, it should give the answer as true in
the first place. Can you help?
 
Try the word Like instead of =. The text you are entering is NOT equal to
the text with the *'s, but the *'s can be used as wildcards in a Like
statement.

If Forms![Challans]![Subform]!Description Like "*nylon*" Then

Also, you enclosed Rate in quotes ("1.9"), is it really a text value? If
not, you shouldn't need the quotes.
 
Thanks a lot, Wayne. You did the trick.
-----Original Message-----
Try the word Like instead of =. The text you are entering is NOT equal to
the text with the *'s, but the *'s can be used as wildcards in a Like
statement.

If Forms![Challans]![Subform]!Description Like "*nylon*" Then

Also, you enclosed Rate in quotes ("1.9"), is it really a text value? If
not, you shouldn't need the quotes.

--
Wayne Morgan
Microsoft Access MVP


I have a query regarding Access programming. I do not
know whether it is a simple or a difficult query.

I have a form which uses a text box by the name 'rate'.
There is combo box 'Customer ID' and 'Description' text
box. I want the rate box to display the value after
evaluating the Customer ID box and the description box.
If I write the word 'nylon' in the description box, it
should take one value and if I write the word 'zinc' in
the description box, it should take the value from the
table. The code that I have written in the afterevent
procedure of the description box is as under:

Private Sub Description_AfterUpdate()

If Forms![Challans]![Subform]!Description = "*nylon*"
Then
Me!Rate = "1.9"
ElseIf Forms![Challans]![Subform]!Description
= "*zinc*" Then
Me!Rate = DLookup
("[Rate]", "Customers", "[CustomerID]=" _
& Forms![Challans]!CustomerID)
Else
Me!Rate = ""
End If

End Sub

The problem is that it just does not catch nylon or zinc.
Like if I write "1 nylon plate of Crest" in the
description column, it should give the answer as true in
the first place. Can you help?


.
 
Back
Top