Selasa, 10 Desember 2013

RE: [MS_AccessPros] Proper use of Switch in Access 2010 Query

 

Bill,

IMO, I would never use an expression with multiple cases. If you can't create a table with the values to update/replace, consider creating a small user defined function that accepts the field values and returns the appropriate value.

Your function might look something like:

Public Function GetLicState(varLicCertCode as Variant, _
     varLicState as Variant, varWorkState as Variant) as Variant

Select Case True
    Case varLicCertCode = "ABC" AND IsNull(varLicState)
        GetLicState = varWorkState
    Case [Other Expression Here]
    Case Else
End Select

End Function

Then, your query would use the function like:

UPDATE ...
SET [Work State] = GetLicState([Lic Cert Code],[Lic State],[Work State])

Duane Hookom MVP
MS Access

----------------------------------------
> From: william.beshlian@alegent.org
>
> Rather than driving myself crazy with a nested IIF statement I want to use the Switch function. After reviewing the syntax for the function I have a question. Will a statement like Switch([Lic Cert Code] = "ABC" AND [Lic State] IS NULL, [Work State]) evaluate properly and place the current value of [Work State] in the [Lic State] field? If not what would? I have multiple cases and a nested IIF statement would get ugly. Thanks in advance!
>
> Bill

__._,_.___
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (2)
Recent Activity:
.

__,_._,___

Tidak ada komentar:

Posting Komentar