Question : Case statement based on query

I am sorry I have no code to give an example of because I am not sure where to start. Here is what I am trying to do. I have a table with two columns. Name and Email. I have about 25 names in this table. I have a combobox on a form the user can select a Name and hit a button. Based on that name I then do a sendobject and mail a report to that person. I know how to do it with a ton of If-Then statements..

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
If Me.Requestor.Value = "Barry Sanders" Then
    DoCmd.SendObject acSendReport, "WOEmailReport", acFormatPDF, "[email protected]", , , "Work Order " & Me.WOID, , False
    DoCmd.Close acForm, "Work Orders", acSaveNo
    DoCmd.OpenForm "Maintenance Log", acNormal

ElseIf Me.Requestor.Value = "Miguel Cabrera" Then
    DoCmd.SendObject acSendReport, "WOEmailReport", acFormatPDF, "[email protected]", , , "Work Order " & Me.WOID, , False
    DoCmd.Close acForm, "Work Orders", acSaveNo
    DoCmd.OpenForm "Maintenance Log", acNormal 

etc....
End If


But I was hoping not to have to type everything out. Thanks for any help you can give me on this. I really do appreciate it.

Answer : Case statement based on query

Field length is not determined by IIF, but the first record of the result, if the first record results in "SoftPak" the SystemType field would be C(7), if the first record is a "Tower" the SystemType is C(5). That's the way foxpro determines field types of an expression/ a computed field.

So cast to the field type and legth you want:
CAST( IIF(...) As C(7)) As SystemType ...

or PAD:
PADR(IIF(...,"SoftPak","Tower"),7) AS SystemType ...

or simply add the needed two spaces to "Tower":
IIF(...,"SoftPak","Tower  ") AS SystemType

Bye, Olaf.
Random Solutions  
 
programming4us programming4us