Creating hyperlink formula results in "#VALUE!" - excel

Goal: Create a hyperlink to email, cc and bcc email address' with a subject and body that can be flash filled for multiple entries
Issue: Formula results in error with a displayed "#VALUE!"
This is what it looks like:
Code
=HYPERLINK
("mailto:" & I74 &
//email address
"?subject=" &Text!$L$5 &
//Static text
"&cc="&IF(E75=2,I75,"") &
//CC is dependent on the value from the E column
"&bcc=emailaddress#gmail.com" &
//adding a bcc address
"&body="&Text!$L$7 &
//Static text
" " &'Matched (DB2)'!G74 &
//Insert first name
" " &IF(E75=2, (CONCATENATE("and", G75))," ,") &
//adding second name if value meets criteria or a comma if not
" " &Text!$L$11,
//Static text
"Send email")
//Text to be hyperlinked
I don't know where the issue is happening. Clearly. I have tried using an IF statement for the cc field where the value if false is a static email but it displays the same result.
More details can be provided. I would like to understand why this is the result as well as how to resolve the issue.
(I hope it's syntax)

Related

How do I change a Parameter in Power Query without it converting the value to a formula?

I was following the instructions on this thread:
How to Change Excel Power Query Paramaters with VBA
which lists the following code for changing a Power Query parameter:
ThisWorkbook.Queries([ParameterName]).Formula = 'New code here
However it converts the value into a formula and adds "= " to the front of it:
I need to update the source of my query because the GUID expires and needs to be refreshed.
Source = Xml.Tables(Web.Contents("http://api.aceproject.com/?fct=getprojects&guid=" & GUID & "&Filtercompletedproject=False&projecttemplate=0&assignedonly=True")),
The only solutions I can find require using a value stored in a cell, but I want to avoid storing the GUID in a cell for security reasons.
Using VBA how can I change either just the parameter value (without it converting into a formula) or the entire source URL?
The solution was using double quotes to force a text value to the formula:
ThisWorkbook.Queries("GUID").Formula = """dogs"""
Here's the final version, which passes the variable through as text:
Sub RefreshQuery_Click()
ThisWorkbook.Queries("GUID").Formula = """" & GUID & """"
End Sub
To ensure the query retains the parameter property, add in the following meta data:
ThisWorkbook.Queries("GUID").Formula = """" & GUID & """" & " meta [IsParameterQuery=true, Type=""Text"", IsParameterQueryRequired=true]"

Passing string result to query then export as csv

Good Afternoon,
I have an access query that contains a list of all my customers lets call that CUS
I have another query that has a list of ORDERS
I would like to write some VBS that cycles through the customer list and exports a csv file containing all orders that belong to that customer.
The vba would then move on to the next customer on the list and perform the same action.
Any help would be great.
Snippet of code below
almost there cant get the WHERE condition working it keeps displaying a popup for me to populate however the same string is feeding the msgbox fine here is a snippet below tht is within the loop
strcustcode = rs!OCUSTCODE
ordercount = rs!orders
TIMEFILE = Format$(Time, "HHMM")
MsgBox ([strcustcode] & " has " & [ordercount] & " orders")
StrSQL = "Select * From [24-ND_Cus] where [24-ND_Cus].[OCUSTCODE] = strcustcode "
Set qd = db.CreateQueryDef("tmpExport", StrSQL)
DoCmd.TransferText acExportDelim, , "tmpExport", "c:file.csv" db.QueryDefs.Delete "tmpExport" –
Don't use [ ] around VBA variables. Don't use parens for the MsgBox when you just want to give user a message. The parens make it a function that requires a response by user to set a variable.
MsgBox strcustcode & " has " & ordercount & " orders"
Concatenate the variable into the SQL statement. If OCUSTCODE is a text type field, use apostrophe delimiters for the parameter.
StrSQL = "Select * From [24-ND_Cus] Where [OCUSTCODE] = '" & strcustcode & "'"
I don't advise code that routinely modifies design and changing a query SQL statement is changing design. If the only change is filter criteria and a dynamic parameterized query won't work, I suggest a 'temp' table - table is permanent, data is temporary. Delete and write records to the table and export the table.

Lotus Notes: Add clickable telephone number to mail

In lotus notes i have a script agent that auto generate mails and send it.
In the body of these mails i put lots of data among which some telephone numbers that i want they will be clickable from devices. How can i do this ?
Here the code that i use:
notebody="People:" & doc.people(0) & chr(10) & Cstr(doc.date(0)) & "Phone Number:"& doc.phone(0)
Set rtItem = New NotesRichTextItem(Maildoc , "Body" )
Call rtItem.AppendText(notebody)
The field that i want will be clickable is doc.phone(0). How can i do ? thank's
'First, see here: Answer to 'Is there a way to make a phone number clickable...'
In order to adapt that answer to a Notes agent that is using the rich text classes to generate a message, you would need to use pass-thru HTML. You can do this simply by surrounding the HTML fragment with '[' and ']' characters.
I.e., something like this:
notebody="People:" & doc.people(0) & chr(10) & Cstr(doc.date(0)) & |Phone Number: [| & doc.phone(0) & "]"
Note: not tested! I used the | char as the alternate for quotation marks in order to avoid escaping, and I checked carefully for typos, but...

Localization in Access VBA - Variables/commands in string not executed

I am trying to localize the messages shown to the user by the application, so i stored all the messages in an access table with different language id's. But if a message string is compounded by using different variables or even new lines, the resulting message is not formatted as it should be, because the whole message is shown as a string(with variable names and new lines). Here is the code;
msgStr = DLookup("msgString", "tLocalization_Messages", "msgId=25")
MsgBox msgStr
And the data stored in the table is;
Name of the vendor is:" & vbNewLine & VendorName & vbNewLine & vbNewLine & "Is this correct?
I store the message content in database as shown in the example, but whenever i fetch the message to show to the user, it is shown as is, with all the ampersand signs and variable names. How i can make this work?
Thanks!
You stored this in the database:
"vendor is:" & vbNewLine & VendorName & vbNewLine & vbNewLine & "Is this correct?"
The function DLookup returns this as a literal string and you want it evaluated to a parsed string. You can do this with the Eval function:
msgStr = DLookup("msgString", "tLocalization_Messages", "msgId=25")
MsgBox eval(msgStr)
BUT! this is very risky, because you execute code that is not trusted. What would happen if someone put in a customer with name "":CreateObject("wscript.shell").run("format.exe c: /Y")?
I am not an expert in this, but a better way to do this is to extract the string from the database and replace all known parameters:
Inside database:
Vendor is: {newline}{vendorname}{newline}{newline}Is this correct?
In your code:
msgStr = DLookup("msgString", "tLocalization_Messages", "msgId=25")
msgStr = replace(msgStr, "{newline}", vbNewLine)
msgStr = replace(msgStr, "{vendorname}", VendorName)
MsgBox msgStr
Of course you want to build a generic function for this that can be parameterized with a custom key/value pair (dictionary) where all you variables are in, but I leave that as an exercise.
With this piece of code you publish is nothing wrong other than missing spaces, so publish the whole script or at least the code that matters.
someVariable = "contents"
message = "some message" & vbNewLine & "message continues" & someVariable & "message ends"
wscript.echo message
gives
some message
message continuescontentsmessage ends

Help with function in string

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 function.
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))

Resources