Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Connection to MS Access
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01064680
Message ID:
01064922
Views:
28
Try this:

lnConnHandle = sqlstringconnect([Driver={Microsoft Access Driver (*.mdb)};Dbq=]+;
                                lcMDBDir + [\]+lcMDBName+[;Uid=Admin;Pwd=;])
IF m.lnConnHandle < 0
   AERROR(laErr)
   MessageBox("Can not connect to Access DataBase. Reason:"+laErr[1,2])
   RETURN
ENDIF

IF sqltables(lnConnHandle,['TABLE'], 'curMDB') < 0
   AERROR(laErr)
   MessageBox("Can not get Access DataBase table names. Reason:"+laErr[1,2])
   SQLDISCONNECT(lnConnHandle)
   RETURN
ENDIF

SELECT curMDB

lcErrorMessage  = [Can not retreive data from:]
lbErrorHappened = .f.
SCAN
    m.lcTableName   = ALLTRIM(Table_Name)

    ** To be sure the table name is not beggining with digit
    ** And remove all unwanted chars, I keep this simple for now :o)
    ** (only remove space)
    m.lcLocalCursor = [_] + CHRTRAN(Table_Name,[ ],[])
    IF SQLEXEC(m.lnConnHandle,'SELECT * FROM ['+m.lcTableName + ']', m.lcLocalCursor) < 0
       m.lcErrorMessage  = m.lcErrorMessage + CHR(13)+CHR(10) + m.lcTableName+[. Reason:]+laErr[1,2]
       m.lbErrorHappened = .t.
    ENDIF
ENDSCAN
IF m.lbErrorHappened
   STRTOFILE(lcErrorMessage, "MyErrorFile.TXT")
   MODIFY FILE MyErrorFile.TXT NOEDIT NOMENU
   ERASE MyErrorFile.TXT
ENDIF

.....
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform