Solved

How do I declare a field in VB Script

Posted on 2006-12-01
4
2,278 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
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…

746 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

10 Experts available now in Live!

Get 1:1 Help Now