Solved

How do I declare a field in VB Script

Posted on 2006-12-01
4
2,314 Views
Last Modified: 2012-06-27
Hi,

I am using the VB Script editor within a canned barcode application (BarTender) to perform some testing.  When the following code is executed, if it is false, the correct value prints.  If it is true, I receive the follow error:
OnProcessData(Line2): : Field name FIRM_LABEL_SETUP.Customer PO # has not been declared.  To declare a field for a script insert DeclareField("FIRM_LABEL_SETUP.Customer PO #") at the top of your script, such that it is not wrapped in any control logic.
if Field("FIRM_LABEL_SETUP.Label Data 1") = empty then
Value = Field("FIRM_LABEL_SETUP.Customer PO #")  
else
Value = Field("FIRM_LABEL_SETUP.Label Data 1")
end if


After following the first message and entering the code that follows, A new error message displays:
The following scrip error war found
OnProcessData(Line 1): : Type mismatch: "DeclareField"


DeclareField("FIRM_LABEL_SETUP.Customer PO #")
if Field("FIRM_LABEL_SETUP.Label Data 1") = empty then
Value = Field("FIRM_LABEL_SETUP.Customer PO #")  
else
Value = Field("FIRM_LABEL_SETUP.Label Data 1")
end if


Any idea?


Thanks
Mc
0
Comment
Question by:mcain_bba
  • 2
  • 2
4 Comments
 
LVL 10

Accepted Solution

by:
Clif earned 500 total points
ID: 18054485
Wrap the field name (within the quotes) in square brackets:

Value = Field("[FIRM_LABEL_SETUP.Customer PO #]")

Use your original code
0
 

Author Comment

by:mcain_bba
ID: 18054693
The error message did not change after adding the [] to the code

if Field("FIRM_LABEL_SETUP.Label Data 1") = empty then
Value = Field("[FIRM_LABEL_SETUP.Customer PO #]")  
else
Value = Field("FIRM_LABEL_SETUP.Label Data 1")
end if
0
 

Author Comment

by:mcain_bba
ID: 18054818
The following code fixed the problem.  I must confess, I do not understand why one field needed to be declared and not the other.

I am going to award some points for working with me.

Thanks
mc


Dim A
A = Field("FIRM_LABEL_SETUP.Customer PO #")

if Field("FIRM_LABEL_SETUP.Label Data 1") = empty then
Value =  A
else
Value = Field("FIRM_LABEL_SETUP.Label Data 1")
end if
0
 
LVL 10

Expert Comment

by:Clif
ID: 18054856
Hmmm...

Maybe it should have been:

Value = Field("FIRM_LABEL_SETUP.[Customer PO #]")

Glad you got it working though.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

863 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

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now