-1

I'm not a programmer, just a little geek, but I'm trying to build up a vb script for a mailing software I use. It should write in the body of the email something depending on the non-numerical values present in two fields of the records of the various contacts, "company" (so, the company name) and "category". What I exactly need is that if the company name is unknown, it just writes nothing but if it is known, then if the category is VENUE, then it writes down "at " but if it is whatever else category, it writes down "with ". Here is what I'm trying but, naturally, it's not working. Thanks in advance for your help!

if Contact.Field("company") = "" Then
  document.write("")
Else
if Contact.Field("category") = "VENUE" Then
document.write("at " & Contact.Field("company"))

if Contact.Field("category") = "INSTITUTION" Then
document.write("with " & Contact.Field("company"))

if Contact.Field("category") = "ASSOCIATION" Then
document.write("with " & Contact.Field("company"))

if Contact.Field("category") = "EV.ORG." Then
document.write("with " & Contact.Field("company"))

if Contact.Field("category") = "AGENCY" Then
document.write("with " & Contact.Field("company")
Ali Sheikhpour
  • 10,475
  • 5
  • 41
  • 82
  • what you mean it is not working? is there any error? or wrong result? – Ali Sheikhpour Mar 18 '23 at 09:13
  • Hi Ali, it doesn't give the desired result... no result at all. Every time I do a modification to the code, I send the email to myself to see if it is working... and it's not. It just leaves an empty space in the email body. – Info Coral Mar 18 '23 at 09:30
  • I'd like to know, basically, how to put there that if Contact.Field("company") is known and Contact.Field("category") = "VENUE", then document.write("at " & Contact.Field("company")), otherwise, if if Contact.Field("company") is known BUT Contact.Field("category") is not "VENUE", then it writes down "with " – Info Coral Mar 18 '23 at 09:35
  • `document.write("")` is a method to push a text into the user interface. If you are using these conditons to prepare an Email body, probably you need a variable to save the result and put it in the email body. Besides `end if` is missing. it may caused an error in background – Ali Sheikhpour Mar 18 '23 at 09:41
  • Yes, I forgot the end if. I added it but it's not working anyway. I'm trying also another solution, the one below. Clearly, I don't expect that it is gonna work, I know it's bad written. I just don't know in which order to put the things and what to put in place of "KNOWN" and how to express that "is not a venue"... – Info Coral Mar 18 '23 at 10:01
  • [code]if Contact.Field("company") = "" Then document.write("") Else if Contact.Field("company") is KNOWN & Contact.Field("category") = "VENUE" Then document.write("at ") Else if Contact.Field("company") is KNOWN & Contact.Field("category") = NOT "VENUE" document.write("with " & Contact.Field("company")) End If[/code] – Info Coral Mar 18 '23 at 10:04

1 Answers1

0

As Ali Sheikhpour stated in the comments, document.write is for displaying something in a web page, and I'm not sure that is what you want to do. If it is, then the code looks like it would work, but could be simplified:

Dim co
co = Contact.Field("company")
If co = "" Then
    document.write("")
Else
    Select Case Contact.Field("category")
        Case "VENUE"
            document.write("at " & co)
        Case "INSTITUTION", "ASSOCIATION", "EV.ORG.", "AGENCY"
            document.write("with " & co)
        Case Else    ' Any other possibilities? Otherwise, nothing will be written.
    End Select
End If

If this isn't working, I suspect you need to replace the document.write with something else, such as file system manipulation. Just where do you want the output to go?

Also, do you really need to write nothing, or is doing nothing enough? I have no vision as to what the rest of the output is or how it should look.

Michael Foster
  • 420
  • 6
  • 12
  • Hi Michael, thanks very much for your help. It's still not working. I need it for a mailing software called "Sendblaster 4". This script should help me to build up a little part of the email body. Basically, I don't want to lose time doing different lists, one for venues and festivals and one for all the others because it would mean also planning two sendings. – Info Coral Mar 22 '23 at 12:23
  • "As Ali Sheikhpour stated in the comments, document.write is for displaying something in a web page" - There are other default (and working) scripts in this software using document.write. – Info Coral Mar 22 '23 at 12:37
  • I still don't understand how the generated strings are supposed to go where you want them. Are you building the email body with a string or something? Just where is `document.write` supposed to write to? The software seems to be basically a mailmerge, and I'm unfamiliar with the syntax specific to it. – Michael Foster Mar 22 '23 at 14:23