Nested IIF in Expression of Calculated Table Field (1 Viewer)

Jonny

Registered User.
Local time
Today, 23:04
Joined
Aug 12, 2005
Messages
144
I can make one condition expression , as shown, however I have more than 10 conditions.
I do prefer to build them as a nested IIF statement in VBA.

What's the right way to do that?
 

Attachments

  • Capture.JPG
    Capture.JPG
    17.9 KB · Views: 90

theDBguy

I’m here to help
Staff member
Local time
Today, 13:04
Joined
Oct 29, 2018
Messages
21,454
Hi. It looks like you're trying to create a calculated field. If so, you can't use VBA at the table level. You actually have a limited amount of functions available to you at this point. What exactly are you trying to calculate?
 

Jonny

Registered User.
Local time
Today, 23:04
Joined
Aug 12, 2005
Messages
144
I'm adding records into employee table. Where new employee is engineer he gets a degree "4" (calculated field).
If new employee architect , het gets "5" , e.t.c..

There are many IIfs..
 

theDBguy

I’m here to help
Staff member
Local time
Today, 13:04
Joined
Oct 29, 2018
Messages
21,454
I'm adding records into employee table. Where new employee is engineer he gets a degree "4" (calculated field).
If new employee architect , het gets "5" , e.t.c..

There are many IIfs..
Hi. I believe IIf() statements can only have up to seven (7) layers (or was it 14?). If you have more than that, and it's probably a better approach anyway, it might be easier to create a separate table of these values and simply link the two tables together in a query.
 

Jonny

Registered User.
Local time
Today, 23:04
Joined
Aug 12, 2005
Messages
144
Assuming it has 7~14 layers, may I build the with CASE statement in VBA as it more readable?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 13:04
Joined
Oct 29, 2018
Messages
21,454
Assuming it has 7~14 layers, may I build the with CASE statement in VBA as it more readable?
Again, though, VBA is not available at the table level, so you can't use it for Calculated fields. I mean, you could try with just one or two options in VBA and see if you can use it in the table. If you can, you can finish building it. If you can't, then you know you didn't waste your time building something you can't use.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 16:04
Joined
Feb 19, 2002
Messages
43,231
Rules on the column in the table is not the way to implement your requirement.

1. Make a separate table of the Roles with RoleID and RoleName
2. Add a RoleID field to the employee table. Set its default to null. If Role is required, make the field required.
3. In the relationship window of the BE database, create a relationship between the two tables and check the enforce RI box.
4. On your data entry form, add a combo that uses the Role table as a control source. If you let the wizard build the combo, it will hide the RoleID field and only display the text.
 

Jonny

Registered User.
Local time
Today, 23:04
Joined
Aug 12, 2005
Messages
144
Thank you , understand, I will try that.
 
Last edited:

Users who are viewing this thread

Top Bottom