×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

I need to output to a field conditionally...
2

I need to output to a field conditionally...

I need to output to a field conditionally...

(OP)


OK, on my form I have  customer ID, customer code, meal type, and meal cost fields. When I enter in a customer ID, the customer code is filled in automatically (that's working). What I need is to display and save to the table the meal cost depending on what the customer code is and the meal type. Here is an example:

If the customer code is 101 and the meal type is brk then meal cost is $1.25
If the customer code is 101 and the meal type is lun then meal cost is  $1.75
If the customer code is 202 and the meal type is brk then meal cost is $2.00
ETC..

Thanks for reading this. I hope it makes sense!


RE: I need to output to a field conditionally...

Well you have it just needs a little VBA tweaking.
here is a function that should work nicely.
Call it like so:

=MealCost([me]![Customer code],[Me]![Meal Type])

--------------------------------
Public Function MealCost(Code, MealType)
    If Code = 101 And MealType = "brk" Then
        MealCost = 1.25
    ElseIf Code = 101 And MealType = "lun" Then
        MealCost = 1.75
    ElseIf Code = 202 And MealType = "brk" Then
        MealCost = 2
    Else
        MsgBox "Customer code is incorrect " & Code, vbExclamation, "Customer Code invalid"
    End If

End Function



DougP, MCP
 dposton@universal1.com
 
 Ask me how Bar-codes can help you be more productive.

RE: I need to output to a field conditionally...

Another solution would be to have a table of values. In a simple example it would be tblMealCost with 3 fields: CustomerCode (number), MealType (text 3), and MealCost (currency).  On your form you state you have already selected the CustomerCode (named RCustomerCode) and MealType (named RMealType) (these could be combo boxes drawing their rowsource from the tblMealCost).  On some event, maybe after selection of MealType (if both CustomerCode and MealType are filled in) you could run the following code in afterUpdate

dim curMealCost as Currency

curMealCost = DLookup("[MealCost]", "tblMealCost", "[CustomerCode] = [RCustomerCode] and [MealType] = [RMealType]")

Me.MealCost.value = curMealCost

This could also be accomplished through a recordset but this example will work.  If you need me to e-mail you an example let me know.
humesgs@smart.net

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close