Skip if field is blank

Home Forums Scripting Windows Script Host Skip if field is blank

This topic contains 2 replies, has 2 voices, and was last updated by Avatar Hobie 8 years, 5 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • Avatar
    brian873
    Member
    #154296

    Hi, I am looking for some help with a VB script I am trying to improve.

    The script runs at logon and pulls out some AD information to create an email signature for the user in Outlook 2003. The script is working fine but I would now like to add in a check so if a field is blank, it does not include that section the in signature.

    The issue is that not all users have fax numbers so I would like to check the fax and only include the line

    objSelection.TypeText “Direct Fax: ” & strFax
    [/CODE]

    if it is not empty.

    Any pointers ?

    Full Script

    [CODE]
    On Error Resume Next

    Set objSysInfo = CreateObject(“ADSystemInfo”)

    strUser = objSysInfo.UserName
    Set objUser = GetObject(“LDAP://” & strUser)

    strName = objUser.FullName
    strTitle = objUser.Title
    strDepartment = objUser.Department
    strCompany = objUser.Company
    strPhone = objUser.telephoneNumber
    strFax = objUser.facsimileTelephoneNumber

    Set objWord = CreateObject(“Word.Application”)

    Set objDoc = objWord.Documents.Add()
    Set objSelection = objWord.Selection

    Set objEmailOptions = objWord.EmailOptions
    Set objSignatureObject = objEmailOptions.EmailSignature

    Set objSignatureEntries = objSignatureObject.EmailSignatureEntries

    objSelection.Font.Name = “Arial”
    objSelection.Font.Size = “10”
    objSelection.Font.Bold = True
    objSelection.TypeParagraph()
    objSelection.TypeText strName
    objSelection.TypeParagraph()
    objSelection.TypeText strTitle
    objSelection.TypeParagraph()
    objSelection.TypeText “Direct Dial: ” & strPhone
    objSelection.TypeParagraph()
    objSelection.TypeText “Direct Fax: ” & strFax

    Set objSelection = objDoc.Range()

    objSignatureEntries.Add “AD Signature”, objSelection
    objSignatureObject.NewMessageSignature = “AD Signature”
    objSignatureObject.ReplyMessageSignature = “AD Signature”

    objDoc.Saved = True
    objWord.Quit
    [/CODE][CODE]
    objSelection.TypeText “Direct Fax: ” & strFax
    [/CODE]

    if it is not empty.

    Any pointers ?

    Full Script

    On Error Resume Next

    Set objSysInfo = CreateObject(“ADSystemInfo”)

    strUser = objSysInfo.UserName
    Set objUser = GetObject(“LDAP://” & strUser)

    strName = objUser.FullName
    strTitle = objUser.Title
    strDepartment = objUser.Department
    strCompany = objUser.Company
    strPhone = objUser.telephoneNumber
    strFax = objUser.facsimileTelephoneNumber

    Set objWord = CreateObject(“Word.Application”)

    Set objDoc = objWord.Documents.Add()
    Set objSelection = objWord.Selection

    Set objEmailOptions = objWord.EmailOptions
    Set objSignatureObject = objEmailOptions.EmailSignature

    Set objSignatureEntries = objSignatureObject.EmailSignatureEntries

    objSelection.Font.Name = “Arial”
    objSelection.Font.Size = “10”
    objSelection.Font.Bold = True
    objSelection.TypeParagraph()
    objSelection.TypeText strName
    objSelection.TypeParagraph()
    objSelection.TypeText strTitle
    objSelection.TypeParagraph()
    objSelection.TypeText “Direct Dial: ” & strPhone
    objSelection.TypeParagraph()
    objSelection.TypeText “Direct Fax: ” & strFax

    Set objSelection = objDoc.Range()

    objSignatureEntries.Add “AD Signature”, objSelection
    objSignatureObject.NewMessageSignature = “AD Signature”
    objSignatureObject.ReplyMessageSignature = “AD Signature”

    objDoc.Saved = True
    objWord.Quit
    [/CODE][CODE]
    On Error Resume Next

    Set objSysInfo = CreateObject(“ADSystemInfo”)

    strUser = objSysInfo.UserName
    Set objUser = GetObject(“LDAP://” & strUser)

    strName = objUser.FullName
    strTitle = objUser.Title
    strDepartment = objUser.Department
    strCompany = objUser.Company
    strPhone = objUser.telephoneNumber
    strFax = objUser.facsimileTelephoneNumber

    Set objWord = CreateObject(“Word.Application”)

    Set objDoc = objWord.Documents.Add()
    Set objSelection = objWord.Selection

    Set objEmailOptions = objWord.EmailOptions
    Set objSignatureObject = objEmailOptions.EmailSignature

    Set objSignatureEntries = objSignatureObject.EmailSignatureEntries

    objSelection.Font.Name = “Arial”
    objSelection.Font.Size = “10”
    objSelection.Font.Bold = True
    objSelection.TypeParagraph()
    objSelection.TypeText strName
    objSelection.TypeParagraph()
    objSelection.TypeText strTitle
    objSelection.TypeParagraph()
    objSelection.TypeText “Direct Dial: ” & strPhone
    objSelection.TypeParagraph()
    objSelection.TypeText “Direct Fax: ” & strFax

    Set objSelection = objDoc.Range()

    objSignatureEntries.Add “AD Signature”, objSelection
    objSignatureObject.NewMessageSignature = “AD Signature”
    objSignatureObject.ReplyMessageSignature = “AD Signature”

    objDoc.Saved = True
    objWord.Quit
    [/CODE]

    Avatar
    Hobie
    Member
    #349697

    Re: Skip if field is blank

    You just need an IF statement:

    If strFax “” then
    objSelection.TypeText “Direct Fax: ” & strFax
    End If

    [/CODE]

    If the strFax is NOT Blank (equal to “”) then add the string.

    Hobie[CODE]
    If strFax “” then
    objSelection.TypeText “Direct Fax: ” & strFax
    End If

    [/CODE]

    If the strFax is NOT Blank (equal to “”) then add the string.

    Hobie

    Avatar
    brian873
    Member
    #281232

    Re: Skip if field is blank

    Many thanks for the quick reply Hobie ! worked a treat :)

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.