>I wrote a code that will create a table (whatever its filename is) to my directory "DATA\". The value of my textbox is "mytable.dbf":
>
>cFileName = CURDIR()+"DATA\"+ALLTRIM(Thisform.txtFileName.Value)
>CREATE TABLE &cFileName (Field1 N(2), Field2 C(8))
>
>- OR -
>
>cFileName = CURDIR()+"DATA\"+ALLTRIM(Thisform.txtFileName.Value)
>CREATE TABLE (cFileName) (Field1 N(2), Field2 C(8))
>
>returns an error message "Field name is a duplicate or invalid."
>
>What could possibly be wrong?
The 2nd statement works fine as long as the directory (CURDIR()+'DATA') exists and the content of the file name value is correct, so I'd start there. When specifying an N field, it's customary to specify two values within parens - the length of the field and the number of places to the right of the decimal place. The following code works fine on my system:
IF ADIR(aFiles,CURDIR()+'DATA','D') = 0
MKDIR (CURDIR()+'DATA')
ENDIF
cFileName = CURDIR() + 'DATA\'+SYS(2015) +'.DBF'
CREATE TABLE (cFileName) (Field1 N(2), Field2 C(8))
Caveat - SYS(2015) returns a name 10 characters in length; if you have a file system that does not support long file names (eg a Novell NetWare 3.x network without the OS2 NameSpace support loaded) this could fail. If you do not have File Create privileges in the CURDIR() or CURDIR()+'DATA' folder, it can fail. If the hard drive is full it can fail. If the directory is marked as read-only or System it can fail. IOW, the CREATE TABLE statement itself is OK, but something in the construction of the file name may make it invalid, or insufficient privileges.