Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Error with oRange
Message
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Environment versions
Visual FoxPro:
VFP 9 SP2
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01516312
Message ID:
01516314
Views:
41
>I have had to rework my entire Excel Automation; the result is that my oRange variable is somehow out of scope.
>What did I do wrong?
>Cecil
>
>
>FOR nMonth = 1 TO lnMonths	&& 12
>	WITH oExcel.ActiveSheet
>		* Select the correct Month's cursor (table).
>		lcMonth=PADL(nMonth, 2, "0")
>		lcCursor=("tmpNearly"+lcMonth)
>		SELECT (lcCursor)
>		SCAN
>			lcCarr_Name = &lcCursor..Carr_Name
>			IF lcCarr_Name <> lcOldCarr_Name	&& Either frist time in, or you have a new carrier.
>				* Move down a row for the new Carrier Name. Makes two rows.
>				oRange = oRange.Offset(1,0)
>				oExcel.ActiveSheet.Cells(lnRow-1,lnCol).Value = "Monthly-" + lcCarrierName
>					* Put the name of the first report in A1.
>				lcAlphaMonth = LEFT(GetAlphaMonth(nMonth),3)
>				.Cells(lnRow-1,lnCol+3).Value = lcAlphaMonth + " " + lcYear
>				* Lay out the Columnn Headers from Left to Right.
>				.Cells(lnRow, lnCol).Value = "Group Name"
>				.Cells(lnRow, lnCol + 1).Value = "GrpID"
>				.Cells(lnRow, lnCol + 2).Value = "Emp. ID"
>				.Cells(lnRow, lnCol + 3).Value = "Benefit"
>				.Cells(lnRow, lnCol + 4).Value = "Month_Billed"
>				.Cells(lnRow, lnCol + 5).Value = "Month_Collected"
>				.Cells(lnRow, lnCol + 6).Value = "Annualized Premium"
>				.Cells(lnRow, lnCol + 7).Value = "Lives"
>			ENDIF
>			*oxcel.ActiveSheet.Cells(lnRow-1,lnCol).Value = "Monthly-" + lcCarrierName
>			WITH oRange
>				* Print the columns/fields to the page. This runs left to right on the default row.
>				.Columns[1].Value = GrpName			&& Group Name
>				.Columns[2].Value = GrpID			&& Group ID
>				.Columns[3].Value = Emp_ID			&& Employer's ID
>				.Columns[4].Value = Benefit			&& Benefit Name.
>				.Columns[5].Value = Billed			&& Monthly Billed Amount By GrpID, Employer.
>				.Columns[6].Value = Collected		&& Monthly Collected amount by GrpID, Employer.
>				.Columns[7].Value = Annualized		&& Annualized Premium.
>				.Columns[8].Value = Lives			&& # of Primary Insured.
>				* Move down one row.
>				oRange = oRange.Offset(1,0)
>			ENDWITH
>			lcOldCarr_Name = &lcCursor..Carr_Name
>		ENDSCAN
>		* Since we've changed months, let's go to the right 9 columns.
>		lnColsOffSetToRight=lnColsOffSetToRight + 9
>		lnCol = lnColsOffSetToRight + 1
>		oRange = .Range("A3:H3").Offset(0, lnColsOffSetToRight)
>	ENDWITH
>ENDFOR
>
With the very first try the oRange variable is not defined (as it's defined inside the IF clause). Also, you don't need to use macro at the top code as you're scanning this exact cursor. Reference the field name without the cursor's prefix.
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform