开发者

Help with function in string

开发者 https://www.devze.com 2022-12-22 11:40 出处:网络
I have a variable, emailBody, which is set to a string stored in a database. The email body is set to a string via a dlookup functio开发者_JAVA技巧n.

I have a variable, emailBody, which is set to a string stored in a database. The email body is set to a string via a dlookup functio开发者_JAVA技巧n.

emailBody = DLookup("emailBody", "listAdditions", "Id = " & itemType)

The string that email body is set to includes an IIf function (which includes a dlookup function). When

?emailBody is entered in the immediate window during runtime, it shows that emailBody is set to the following string:

The new commodity is" & Iif(dlookup("IsVague", "CommodityType", "Description= " & newItem)="1", "vague.", "not vague.")

However, I want the dlookup and IIf functions to be evaluated and their results stored in the string. How do I properly format the emailBody string ("the new commodity...") in my database so that the functions will be evaluated and the results stored in the emailBody variable?


Your question is a bit unclear, but if [Id] (Or [Description]) is a string, then you Dlookup must be like this:

 emailBody = DLookup("emailBody", "listAdditions", "Id = '" & itemType & "'")

or

 emailBody = DLookup("emailBody", "listAdditions", "Id = """ & itemType & """")

That is, your constant should be surrounded by quotes. You can either use ' (single quote) or "" (doubled double quote).


I am somewhat concerned about the value of newitem, but in general you can use Eval:

s = """The new commodity is"" & " _
& "Iif(dlookup(""IsVague"", ""CommodityType"", ""Description= "" & newItem)=""1"", ""vague."", ""not vague."")"
s2 = Eval(s)

I am not sure that this is the way to go, think about it.


So you have this exact string stored in a table field, and you want Access/VBA to evaluate it, correct?

"The new commodity is " & Iif(dlookup("IsVague", "CommodityType", "Description= " & newItem)="1", "vague.", "not vague.")

If so, try the Eval() command:

emailBody = Eval(DLookup("emailBody", "listAdditions", "Id = " & itemType))
0

精彩评论

暂无评论...
验证码 换一张
取 消