Missing Field Error Occurs After the Use of the Openfile Function

The following code is from a database called “Inquiries”:

if (info(“files”) notcontains “Customers”)
openfile “Customers”
endif

if emptycell(«Terms»)=false()
message “Terms field is empty.”
endif

If the Customers database is not open, the openfile function will open the Customers database, and the following error will occur.

“sizeof( function error: no field or variable named “Terms”.”

However, the field “Terms” does exist in the Inquiries database. This procedure will recognize that the field “Terms” exits, as long as it doesn’t have to open the database “Customers”.

My workaround solution is the following.

local iTerms
iTerms=«Terms»

if (info(“files”) notcontains “Customers”)
openfile “Customers”
endif

if sizeof(iTerms)=0
message “Terms field is empty.”
endif

FYI, both databases are shared.

Why is this error occurring?

The OpenFile statement is making the Customers database the active database, and Customers apparently doesn’t have a field named Terms.

In your workaround you are setting the iTerms variable to the value of your Terms field before opening Customers. iTerms is a local variable which will be in scope as long as that procedure is running, regardless of which database is active.

You are correct. I see it now. Thank you.