473,395 Members | 1,680 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Case function in Access?

Ok, I have almost masted the IF and IIF functions but these take up to many fields in a query. Suppose I have 10 different sales people in my database that want to receive an e-mail when their orders are completed. I started out doing this using a command button that asks the user to enter the address, subject, and body. This worked fine but I want all that data entered automatically. So, I need something on the form or query that holds the e-mail address according to which salesperson it is. I went to what I know and that is IIf functions.
in the query:
Expand|Select|Wrap|Line Numbers
  1.  IIf ([salesperson] = "DB", "donaldburtrum@kcd.com", "") 
that works fine as well except I have to make a field in the query for every one of my sales people.
What I want is one singel Field that test for all the possible abbreviated names and gives the correct e-mail address to the record. Like a IIf function with multiple conditions? I'm not sure if Access will take a case statement?
I just need the name of the function to use in the query. Or, should I being doing this all in VB?
Feb 1 '07 #1
4 3412
Rabbit
12,516 Expert Mod 8TB
If I understand you correctly, you can just make another table that holds Name and E-mail address values. And then you can have a query joined on Name.
Feb 1 '07 #2
Connect the queries?
Here is the original code for entering the information.
Expand|Select|Wrap|Line Numbers
  1. Private Sub CMDemail_Click()
  2. Dim strToWhom As String
  3. Dim strSubject As String
  4. Dim strBody As String
  5. Dim strMsgBody As String
  6. Dim intSeeOutlook As Integer
  7.  
  8. strToWhom = InputBox("Enter recipient's e-mail address.")
  9. strSubject = InputBox("Enter Subject.")
  10. strBody = InputBox("Enter Text.")
  11.  
  12. DoCmd.SendObject , , , strToWhom, , , strSubject, strBody, intSeeOutlook
  13. x = MsgBox("Email has been sent")
  14.  
  15. End Sub 
Now I can make all of this work with data that is displayed in the form.
Something like this.
Expand|Select|Wrap|Line Numbers
  1. Private Sub CMDemail_Click()
  2. Dim strToWhom As String
  3. Dim strSubject As String
  4. Dim strBody As String
  5. Dim strMsgBody As String
  6. Dim intSeeOutlook As Integer
  7.  
  8. 'this associates only one abbreviation with an email address
  9. IIf [salesperson] = "JB", strToWhom = "jbob@soandso.com", ""
  10. 'the subject for this information
  11. strSubject = "Order Ready"
  12. 'the information about the completed order(sytax is wrong ill fix it)
  13. strBody = [CUSTOMERNAME], [WO NUMBER], "is completed"
  14.  
  15. DoCmd.SendObject , , , strToWhom, , , strSubject, strBody, intSeeOutlook
  16. x = MsgBox("Email has been sent")
  17.  
  18. End Sub
I found this code on here by the way thanks.
There are 10 possible strings that can be put into [SALESPERSON] and 10 different e-mail addresses that go with them. So, if [salesperson] does not equal JB then it gives me an Outlook composed message with the address blank because it doesn't have the info to send yet.

I'm thinking I need look at something like a Loop or Case Function. I'll work on it tonight and report my findings this evening.
Feb 1 '07 #3
Rabbit
12,516 Expert Mod 8TB
I misunderstood your original posting.
Sure, you could use a select case but that's a hassle to maintain.
Instead you could have a table that stores Name and E-mail information and use the DLookup function to find the e-mail address from the table.

Expand|Select|Wrap|Line Numbers
  1. DLoopup("EMail", "tbl_EMail", "Name = '" & [SalesPerson] & "'")
Feb 1 '07 #4
NeoPa
32,556 Expert Mod 16PB
Rabbit, Always remember to use code tags. Notice how you can differentiate the different types of quotes in your example.

KC, listen to this guy, he's talking sense (again). I would have posted a response but I found it was already done fine. You need to include a table with this data in your design.
Feb 2 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: noah | last post by:
Can anyone think of a way to make array keys case insensitive? An option on any recent PHP would be to convert all array keys to lowercase using the standard array_change_key_case() function. As...
2
by: JMCN | last post by:
hello i have your basic select case question. i created a combo box and save it as a query. so whenever the user selects the value and clicks the export button, the select case should then export...
4
by: Terencetrent | last post by:
I having been using Access '97/2002 for about 4 years now and have never really had the need or the time to learn visual basic. Well, I think the time has finally come. I need help with Visual...
6
by: Michael | last post by:
Hi, all, I want to keep the address of one static array in some place in order to access the content of this array in other module. Which way should I use? I try it in this way: find one DRAM...
6
by: kelvlam | last post by:
Hello all, I'm still a bit new with JavaScript, and I hope the guru here can shed some light for me. It's regarding handling cookie and the case-sensitive nature of JavaScript itself. My...
2
by: philbrierley | last post by:
What is the easiest way to write SQL that Access understands to achieve simple standard SQL query below? Thanks in Advance, Phil SELECT
6
by: ccsoupy22 | last post by:
For simplicity sake, here are the basics of the query I am stumped on... Type: Select query Name: ColorCells Below is a partial list of the "Cases" for the code (I did not think there was...
3
by: emalcolm_FLA | last post by:
Hello and Thanks in advance for any help. I have been tasked with rewriting a christmas assistance database using Access 2003. The old system used pre-assigned case numbers to identify...
1
weaknessforcats
by: weaknessforcats | last post by:
C++: The Case Against Global Variables Summary This article explores the negative ramifications of using global variables. The use of global variables is such a problem that C++ architects have...
11
by: Rafe | last post by:
Hi, I'm working within an application (making a lot of wrappers), but the application is not case sensitive. For example, Typing obj.name, obj.Name, or even object.naMe is all fine (as far as...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.