Arguement not optional in vb module

G

gdonald20

Hi

I have an after update event on a field on my people form.

When i try to debug the code i get an "Argument not optional" error in
relation to the IIf statement.

I used the same code in an update query and it worked perfectly.

PE_Initials = (Left([PE_First_Name], 1) & IIf(InStr(1, [PE_First_Name],
" ") <> 0, Mid([PE_First_Name], InStr(1, [PE_First_Name], " "), 2)))

Can anyone tell me why this doesn't work in the code module.

Thanks

Gillian
 
R

Robert Morley

PE_Initials =
(
Left([PE_First_Name], 1) &
IIf(
InStr(1, [PE_First_Name], " ") <> 0,
Mid(
[PE_First_Name],
InStr(1, [PE_First_Name], " "),
2
)
)
)


Doesn't IIf require 3 arguments? I only see two...the Instr comparison, and
the Mid.


Rob
 
D

david epsom dot com dot au

IIF works differently in a code module. Both options are required,
and both are evaluated.

In a query, you can have

a: IIF(x,1)
b: IIF(true,1,1/0)

but neither works in a code module.

(david)
 
D

DavidAtCaspian

And you may find it easier to write and support if you used an If / else/
endif consrtuct, or even a select case.

Certainly easier to read!



david epsom dot com dot au said:
IIF works differently in a code module. Both options are required,
and both are evaluated.

In a query, you can have

a: IIF(x,1)
b: IIF(true,1,1/0)

but neither works in a code module.

(david)


gdonald20 said:
Hi

I have an after update event on a field on my people form.

When i try to debug the code i get an "Argument not optional" error in
relation to the IIf statement.

I used the same code in an update query and it worked perfectly.

PE_Initials = (Left([PE_First_Name], 1) & IIf(InStr(1, [PE_First_Name],
" ") <> 0, Mid([PE_First_Name], InStr(1, [PE_First_Name], " "), 2)))

Can anyone tell me why this doesn't work in the code module.

Thanks

Gillian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top