Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Luca Moioli
  Where is Luca Moioli?
 Venezia
 Italy
 Luca Moioli
 To: Suresh Adhikari
  Where is Suresh Adhikari?
 New Delhi
 India
 Suresh Adhikari
 Tags
Subject: RE: THISFORM can only be used within a metho
Thread ID: 345164 Message ID: 345176 # Views: 34 # Ratings: 0
Version: Visual FoxPro 9 SP2 Category: Microsoft Office Automation
Date: Saturday, May 19, 2012 3:40:42 PM         
   


> > Dear friends,
> > I have a procedure using Excel.
> > In the form's Init I initialize Excel object:
> >
> >
> >
> > thisform.oExcel=CreateObject("Excel.Application")
> > thisform.oBook=thisform.oExcel.Workbooks.Open(m.dir_xls+"CONFERME.xls")
> > thisform.oBook.WorkSheets(1).Activate()
> > 

> >
> > When I call .Cells.Find method
> >
> >
> > 			SCAN all
> > 				WITH thisform.oBook.WorkSheets(1)
> > 					.Cells(1,1).Select
> > 					IF NOT EMPTY(MyValue)
> > 						m.MyValue=chrtran(ALLTRIM(MyValue),CHR(96),"'")
> > 						wait window nowait noclear m.MyValue
> > 						IF .Cells.Find(ALLTRIM(m.MyValue)).Activate
> > 							.Cells(thisform.oExcel.ActiveCell.Row,16).Value="ok"
> > 						ENDIF
> > 					endif
> > 				ENDWITH 
> > 			endscan
> > 

> >
> > I get a strange error:
> >
> > THISFORM can only be used within a method (Error 1929)
> >
> > Please, what is wrong?
> > Thank you very much
>
>
> Try removing "thisform"
>
>
> public oExcel,oBook
> oExcel=CreateObject("Excel.Application")
> oBook=oExcel.Workbooks.Open(m.dir_xls+"CONFERME.xls")
> oBook.WorkSheets(1).Activate()
> 

>
> .Cells.Find method
>
>
> SCAN all
>   WITH oBook.WorkSheets(1)
>      .Cells(1,1).Select
>         IF NOT EMPTY(MyValue)
>            m.MyValue=chrtran(ALLTRIM(MyValue),CHR(96),"'")
>              wait window nowait noclear m.MyValue
>              IF .Cells.Find(ALLTRIM(m.MyValue)).Activate
> 		.Cells(oExcel.ActiveCell.Row,16).Value="ok"
>     	     ENDIF
> 	endif
>    ENDWITH 
> endscan
> 






Dear Suresh,
I fixed error.
The problem was not THISFORM statement, but .Cells.Find(ALLTRIM(m.MyValue) that returns .NULL. if it does not find MyValue in Excel. The message was not quite pertinent to the error.
So I solved with:

SCAN all
	WITH thisform
		.oBook.WorkSheets(1).Cells(1,1).Select
		IF NOT EMPTY(MyValue)
			m.MyValue=chrtran(ALLTRIM(MyValue),CHR(96),"'")
			wait window nowait noclear m.MyValue
			IF NOT ISNULL(.oExcel.Cells.Find(m.MyValue))		
				.oExcel.Cells.Find(m.MyValue).Activate
				.oBook.WorkSheets(1).Cells(.oExcel.ActiveCell.Row,16).Value="si"
			ENDIF
		ENDIF
	ENDWITH 
ENDSCAN 



ENTIRE THREAD

THISFORM can only be used within a metho Posted by Luca Moioli @ 5/19/2012 9:29:28 AM
RE: THISFORM can only be used within a metho Posted by Suresh Adhikari @ 5/19/2012 11:14:31 AM
RE: THISFORM can only be used within a metho Posted by Luca Moioli @ 5/19/2012 3:40:42 PM