View Full Version : Change IF Statement


Matizo
12-17-2009, 02:49 AM
Hi,

Could someone please add to the IF Statement below one more field: BusinessName. Besically, if the Forename and Surname are NULL the BusinessName show appear and vice versa.

Client Name: IIf(IsNull([Surname]),IIf(IsNull([Forename]),[Forename]),IIf(IsNull([Forename]),[Surname],[Forename] & " " & [Surname]))


Thank you guys!

neileg
12-17-2009, 03:14 AM
How about Client Name: IIf(IsNull([Surname]&[Forename]),[BusinessName]), [Forename] & " " & [Surname]))

Matizo
12-17-2009, 04:07 AM
I get an error when I try to input this expression.
Error: "The expression you entered contains invalid syntax".


Thanks!

wilpeter
12-17-2009, 01:26 PM
Looks like you didn't get a follow-up answer. Try this:
ClientName: IIf(IsNull([Surname]),IIf(IsNull([Forename]),[BusinessName],[Forename],IIf(IsNull([Forename]),[Surname],[Forename]&" "&[Surname]))
Sorry for the delay.

Matizo
12-18-2009, 01:33 AM
Hi,

Thanks for the reply, but I'm still getting an error "wrong number of arguments".

Cheers

namliam
12-18-2009, 01:43 AM
Suspect neil was a bit to quick on the copy paste...
Two brackets to many...
Client Name: IIf(IsNull([Surname]&[Forename]),[BusinessName], [Forename] & " " & [Surname])

wilpeter
12-18-2009, 04:19 AM
My apologies also. I left out the closing parenthesis before the second ISNULL or it would have worked. The only drawback with the shorter version, namliam, is that if there is only a surname, there'll be a blank space before it. Otherwise, it serves well.

Matizo
12-18-2009, 05:34 AM
Thanks guys, it works now.

One more question, why is my delete query not working if I use the SQL below?

DELETE tblAllocations.*, ([tblAllocations_1].[EmployeeNo]=[tblAllocations].[EmployeeNo])
FROM tblAllocations, tblAllocations AS tblAllocations_1
WHERE (((([tblAllocations_1].[EmployeeNo]=[tblAllocations].[EmployeeNo]))=True));


THANKS!

neileg
12-21-2009, 01:20 AM
Suspect neil was a bit to quick on the copy paste...
Two brackets to many...
Client Name: IIf(IsNull([Surname]&[Forename]),[BusinessName], [Forename] & " " & [Surname])Oops, too quick as you say namliam.
:o

neileg
12-21-2009, 01:25 AM
Thanks guys, it works now.

One more question, why is my delete query not working if I use the SQL below?

DELETE tblAllocations.*, ([tblAllocations_1].[EmployeeNo]=[tblAllocations].[EmployeeNo])
FROM tblAllocations, tblAllocations AS tblAllocations_1
WHERE (((([tblAllocations_1].[EmployeeNo]=[tblAllocations].[EmployeeNo]))=True));


THANKS!
Doesn't make sense to me. What are you trying to do?

Matizo
01-04-2010, 03:38 AM
Basically I'm trying to delete double allocations. for example employee A cannot be allocated twice to the same job. Hence, I don't know how to prevent double allocations I'm trying to run the query to delete them when the occur...


Cheers!

namliam
01-04-2010, 07:18 AM
Lets start at the base, How would you find duplicates?

Matizo
01-05-2010, 04:49 AM
I think it's solved :)
http://www.access-programmers.co.uk/forums/showthread.php?t=185438