Use Field content as VBA

rtdc

Registered User.
Local time
Today, 18:41
Joined
Feb 27, 2007
Messages
55
This is probably a silly question but its Sunday and my brain hurts lol.

I want to get the literal value from a field in code, what I want to do is construct in a memo field a email text with the vba code in so when called in my email module it will act on the code given. E.g. if I type this in the field

“Dear ” & ‘” & SAL & “’ & “. How are you?”

(SAL being what I call the name field in the SQL I am calling to populate email)

when the code is run using sendobject acsendnoobject or using a outlook calling module it will read in the email as

Dear Fred. How are you

Not

“Dear ” & ‘” & SAL & “’ & “. How are you?”

Which is what I am getting

I have requirement to be able to construct emails where the recipients name is used in the email text, these emails will be mail shots so there will be hundreds so the name cannot just be typed in.

Anyone have a clue how to lookup the content of the field and get VBA to use it as its written not just put it in the email body as a string?
 
I think that your problem is in the sequence of single quotes & double quotes.

I use the following code to lookup queries, may be it will help.

sql = "select * from areascoveredbysocieties where Area = '" & AreatoMatch & "'"

It reads singlequote double quote (nospace) space & space areatomatch space & double quote single quote (nospace)

Regards
 
Hi

The code I am using is

Set Myset = CurrentDb.OpenRecordset("SELECT * FROM [EmailText_tbl] WHERE ((([EmailText_tbl].ContentID)= " & S & "))")

e.g. S = 1

SAL = Myset![SAL]

Which is returning '" & SAL & "' as text in the email and what I want is to be able to use SAL so in the VBA the same as if i typed '" & SAL & "' so a full formated email could be written in a memo field and then VBA will read it as code.

Cheers
 
I would really re-think the idea. Arbitrary code execution opens the door to bad things. I could write VBA to delete all files or something like that. Do you really want to give your users that much power?

While it is certainly possible to do arbitrary code execution by using Eval() function or Application.Run method, I would probably look at other ways to avoid the need to do this.

One example would be to provide the users a memo so they can start filling the content of email and if they need to look up something, supply them with comboboxes/listboxes to select different tables/columns then the value they want to insert into the memo. In case where you want a field you can change for every record, look into mail merge supported by Word and automating it from Access instead.

I'm sure if you look it through, you'll find solutions that doesn't require the arbitrary code execution.
 

Users who are viewing this thread

Back
Top Bottom