Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Need help with a VBScript to evaluate text field values

Posted on 2012-03-15
Medium Priority
Last Modified: 2012-03-27
My existing script checks 2 text fields, MEDI_INPATIENT_FILE and MEDI_MEDICAL_FILE to see if they have a value of N/A and compares this value to its corresponding integer fields, MEDI_MEDICAL_COUNT and MEDI_INPATIENT_COUNT.  This validation is working to assure that if the text value is not N/A, that the integer field value is greater than zero (via the CheckCDate function).

What I need to do now is check and see if BOTH the text fields to assure that AT LEAST ONE of them has a value <> to N/A or Null.

Now, I need a Function to take care of this.  The reason I need a Function is that I will have other text fields to check (like this Medical example) that have scores of text fields like MEDI_MEDICAL_FILE..  In this small example, the “Medical” data type only has 2 such text fields.  Others could have up to 50.  Also, since I’m already going to the database in the existing script to obtain the text field value, I don’t want to do it a second time.

The objective is to go through each text field and assure that at least one has a value that is not N/A or null.

Dim currentRecord
Dim dApproval, dCdate
Dim strIssueID, strFileName
Dim nFileCount, nFileNameValue, nFileNameSum
strFileDefault = "n/a"
If Ext.ShellHasProp( "item" ) Then
      Set currentRecord = Shell.item
      Set currentRecord = Nothing
End If
Call GetFieldValue( currentRecord, "ISSUEID", strIssueID)
Call Ext.LogInfoMsg( "This is the value of the current record or Shell.Item: " & strIssueID)
Call GetFieldValue( currentRecord, "MEDI_MEDICAL_FILE", strFileName)
Call GetFieldValue( currentRecord, "MEDI_MEDICAL_COUNT", nFileCount)
Call CheckFileCount(strFileName, nFileCount)
Call intFileNameCounter(strFileName)
Call GetFieldValue( currentRecord, "MEDI_INPATIENT_FILE", strFileName)
Call GetFieldValue( currentRecord, "MEDI_INPATIENT_COUNT", nFileCount)
Call GetFieldValue( currentRecord, "MEDI_MEDICAL_CDATE", dCdate)
Call GetFieldValue( currentRecord, "MEDICAL_LF_APPROVAL_DATE", dApproval)
Call CheckCDate(dCdate, dApproval)
Call GetFieldValue( currentRecord, "MEDI_INPATIENT_CDATE", dCdate)
Call GetFieldValue( currentRecord, "MEDICAL_LF_APPROVAL_DATE", dApproval)
Call CheckCDate(dCdate, dApproval)
Question by:impala6
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
LVL 13

Expert Comment

by:Chris Raisin
ID: 37727787
This is trickier than I first thought.

Stand By....

Chris (Australia)
LVL 15

Assisted Solution

markdmac earned 400 total points
ID: 37729532
Here is a simple example to do what you ask


WScript.Echo CheckIsNull (test1a,test1b)
WScript.Echo CheckIsNull (test2a,test2b)
WScript.Echo CheckIsNull (test3a,test3b)
WScript.Echo CheckIsNull (test4a,test4b)

Function CheckIsNull(f1,f2)
      If Len(f1) > 0 Or Len(f2) > 0 Then
            CheckIsNull = "Not Null"
            CheckIsNull = "Null"
      End If
End Function
LVL 13

Expert Comment

by:Chris Raisin
ID: 37734781
I don't think that will work.

Null is not the same as "n/a" or empty.

Stand By....
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 13

Accepted Solution

Chris Raisin earned 1600 total points
ID: 37734802
How about this (I assume "Null" means empty)

You could (example only) use it thus:

         Field3.text = iif( NotNullOrNA(Field1.text, Field2.text),"Has Value","NoValue")
If "Null" will actually be stated in the field then the code would change slightly.
(Please advise if that is so)


Option Explicit
Public Function NotNullOrNA(strField11 As String, strField2 As String) As Boolean
  'Function checks to see whether at least ONE of the two
  'text fields is not empty and has a value <> "n/a"
  '(By default it returns "False")

  strField1 = Trim(LCase(strField1))
  strField2 = Trim(LCase(strField2))
  If Len(strField1) > 0 Then
    If strField1 <> "n/a" Then
      NotNullOrNA = True
      Exit Function    'no need to test any further
    End If
  End If
  If Len(strField2) > 0 Then
      If strField2 <> "n/a" Then
        NotNullOrNA = True  
        'no need to exit function here since there is no further testing  
      End If
    End If
  End If
End Function

Open in new window

LVL 15

Expert Comment

ID: 37734882
My code should work for you. Please test and report back.  Also feel free to supply a sample source file for further help.

Author Comment

ID: 37742924
That's intriguing, Mark - but in most cases I'm checking 30-40 text fields each with a unique field name so the Function would be huge.  Is there a way to get this to a few reusable lines of code so that I can have one variable representing the "file name" field?

I've attached a script that is doing what I need it to do, but I'm hoping there is a way to scale it down a bit.
LVL 15

Expert Comment

ID: 37744954
Why would the function be any larger than the same I provided?  Pass it the names of any two variables and it will tell you if at least one has a value as you stated you were trying to do.
LVL 13

Expert Comment

by:Chris Raisin
ID: 37745575

Have you tried my code? It returns false if the value at least one has a value that is not "n/a" is there or  Empty (as requested).


Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently, an awarded photographer, Selina De Maeyer (, completed a photo shoot of a beautiful event ( in An…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

660 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question