Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. sponsors. rss.
 From: Blair Lawrence
  Where is Blair Lawrence?
 London
 Canada
 Blair Lawrence
 To: tushar
  Where is tushar?
 Panaji
 India
 tushar
 Tags
Subject: RE: Excel to VFP to SQL Task
Thread ID: 225062 Message ID: 226693 # Views: 42 # Ratings: 0
Version: Visual FoxPro 9 Category: Databases, Tables and SQL Server
Date: Monday, May 04, 2009 3:12:26 PM         
   


> How many of all these points can you do successfully? If the answer is none, then I would suggest you search this site for "books" and "videos"
>
> Regards
> Tushar
>
> > This is the task:
> > *)-------------------------------------------------------------
> > *)Add a button to Parent form called 'Import Detail'.
> > *) Button will only enable if STATUS (txtStatus) box = 'Started'.
> > *) When Clicked popup box - user to confirm import of excel data to header record.
> > *) If 'Yes'- invoke file lookup with new Child dialog Window.
> > *) Lookup defaults to last used path based on program UserID.
> > *) Disk file path will be saved to the Program UTUSER user memo whenever function is envoked.
> > *) If new user - current path is Program system path to the Program folder.
> > *) When spreadsheet is selected - import each row.
> > *) Import from spreadsheet until blank line is found in Account# (Column A).
> >
> > *) CCA - Validate Account# as valid current GL account (GLMAST).
> > *) CCB - If not Valid GL Account 'Error Message - Row will be skipped'.
> > *) CCD - Remove any dashes from importing Account#.
> > *) CCE - If column Account#(column A) evaluates as number convert to string.
> > *) CCF - [Transaction Description] (Column B) must not be blank and must evaluate to string.
> > *) CCG - Debit & Credit (Column C & D) must be numeric and one column must be >0 with no value >0 in both.
> >
> > *) Check Code from CCA to CCG before inserting row into SQL dbo.GLITEM table via document automation.
> >
> > *) Entries in Debit & Credit (Column C & D) must match. IF NOT EQUAL the VFP Parent Form will require additional line item or change to existing lines to achieve balance before transaction is posted.
> > *) Decimal precison is !> M2M currency decimal.
> > *) Display MsgBox with a Line count and Credit & Debit sum.
> > *)-------------------------------------------------------------
> >



This is what I have so far...and yes it works importing the excel table to vfp.

SET TALK OFF
LOCAL lcXLBook AS STRING, lnSQLHand AS INTEGER, ;
lcSQLCmd AS STRING, lnSuccess AS INTEGER, ;
lcConnstr AS STRING
CLEAR

lcXLBook = [C:\GLJEascTest.xls]

lcConnstr = [Driver=] + ;
[{Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};] + ;
[DBQ=] + lcXLBook

IF !FILE( lcXLBook )
? [Excel file not found]
RETURN .F.
ENDIF
*-- Attempt a connection to the .XLS WorkBook.
*-- NOTE: If the specified workbook is not found,
*-- it will be created by this driver! You cannot rely on a
*-- connection failure - it will never fail. Ergo, success
*-- is not checked here. Used FILE() instead.
lnSQLHand = SQLSTRINGCONNECT( )

*-- Connect successful if we are here. Extract data...
lcSQLCmd = [SELECT * FROM "SHEET1$"]


lnSuccess = SQLEXEC( lnSQLHand, lcSQLCmd, [xlResults] )
? [SQL Cmd Success:], IIF( lnSuccess > 0, 'Good!', 'Failed' )
IF lnSuccess < 0
LOCAL ARRAY laErr[1]
AERROR( laErr )
? laErr(3)
SQLDISCONNECT( lnSQLHand )
RETURN .F.
ENDIF


*-- Show the results
SELECT xlResults
BROWSE NOWAIT
SQLDISCONNECT( lnSQLHand )

The connection to excel is unfortunately manual when I tried coding the connection it always failed.

The other problem I have now is parsing the first excel column to remove the hyphens. It is currently loading into vfp as a memo field.

I found this but I am not sure where to place the code :SEMyString = Replace(MyString, "-","")
( all this code is running from a command button click event)



COMPLETE THREAD
Excel to VFP to SQL Task Posted by Blair Lawrence @ 4/17/2009 9:13:43 PM
RE: Excel to VFP to SQL Task Posted by tushar @ 4/18/2009 7:16:39 AM
RE: Excel to VFP to SQL Task Posted by Blair Lawrence @ 5/4/2009 3:12:26 PM
RE: Excel to VFP to SQL Task Posted by shi yangyang @ 10/23/2009 8:27:53 AM
RE: Excel to VFP to SQL Task Posted by Blair Lawrence @ 10/23/2009 2:59:29 PM
RE: Excel to VFP to SQL Task Posted by shi yangyang @ 10/26/2009 2:00:04 AM