Search code examples
excelvisual-foxpro

APPEND FROM excel sheet gives strange error


I have a problem with the APPEND FROM statement in Visual FoxPro. I cannot do an APPEND FROM an excel sheet without getting this error:

Function name is missing (

I'm working on processing some legacy data stored in a FoxPro database. I'm reading it, processing it in .NET, and then writing it back to a new FoxPro database. However, the writing part is not working. Unfortunately using another database is not an option. And yes, I am a FoxPro newbie.

I do get INSERT statements to work, but it would be useful if I could get APPEND FROM an external file to work as well, AND also be able to hydrate memo fields. Afaik you can't do that with CSV files in FoxPro, only Excel and some other formats - but not CSV.

To demonstrate the problem I'm using the Address Book sample database that comes with Visual Foxpro.

I run this query in the query window in V.FP:

USE "ADDRESS BOOK!ADDRESSES"
APPEND FROM D:\tmp\excel_data2.xls FIELDS (addressid, firstname) DELIMITED XLS

The .xls file is a Excel 97-2003 workbook and looks like this:

A   | B
------------------------
23  | Sample 1
------------------------
24  | Sample 2 

I think the syntax should be correct according to this doc: http://msdn.microsoft.com/en-us/library/aa977271(v=vs.71).aspx

However, running this query just gives me the error about "Function name is missing (" . I've tried all sorts of rewrites and variations of this query that I could think of, but I just can't figure out what the problem is. Any help would be appreciated, thanks.


Solution

  • Not to steal the show, but this is how I got it working:

    Ensure the XLS file is stored in the Excel 5.0/95 format (basically an ancient Excel format, but more than sufficient for data entry).

    Close the Excel file, otherwise you will get an error about the file being locked/open in another app.

    I used the following amended APPEND FROM statement and it worked:

    USE "ADDRESS BOOK!ADDRESSES"
    APPEND FROM D:\tmp\excel_data2.xls FIELDS addressid, firstname XLS