|
-
Aug 4th, 2012, 09:20 AM
#1
Thread Starter
Lively Member
Extract the value only for few columns dynamically from result set
Hi All,
I have table with following Columns:
Banker
Status
Week1
Week2
Week3
Week4
......
Week48
Week49
Week50
Budget
YearMonth
I need to extract the value only for few columns dynamically from the result set. I have written the following code:
Code:
i = 0
strColumnsSQL = "Week" & CStr(gsReportingWeekNo)
Do While i < 4
i = i + 1
strColumnsSQL = strColumnsSQL & ",Week" & CStr(gsReportingWeekNo) - i
Loop
strSelectSQL = "SELECT tbl_Consol_Weekly_NNA.[Banker], tbl_Consol_Weekly_NNA.Exclude, " & _
strColumnsSQL & _
" FROM tbl_Consol_Weekly_NNA " & _
" INNER JOIN tbl_Mapping ON tbl_Consol_Weekly_NNA.[Banker] = tbl_Mapping.[Revenue Producer]" & _
" WHERE [YearMonthWeek] = '" & txtReportingMonth & CStr(gsReportingWeekNo) & "'" & _
" AND " & strWhereCondition & "= '" & sTeamRegionName & "' " & _
" AND tbl_Mapping.[Exclude] = False " & _
" ORDER BY " & strWhereCondition & ", tbl_Consol_Weekly_NNA.[Private Banker]"
Set rsTmp = gsPnPDatabase.OpenRecordset(strSelectSQL)
i = 0
ColumnStart = ColumnStart + 1
Do While i < 4
i = i + 1
objXLSheet.Cells(RowStart, ColumnStart) = "Week " & CStr(gsReportingWeekNo) - i
ColumnStart = ColumnStart + 1
Loop
rsTmp.MoveLast
recount = rsTmp.RecordCount
For count = 1 To recount
ColumnStart = 1
objXLSheet.Cells(RowStart, ColumnStart) = rsTmp.Fields(0)
ColumnStart = ColumnStart + 1
i = 0
Do While i < 4
i = i + 1
objXLSheet.Cells(RowStart, ColumnStart) = " & rsTmp.Fields(" & i & ") &" '--> Not Returning the value
ColumnStart = ColumnStart + 1
Loop
ColumnStart = ColumnStart + 1
RowStart = RowStart + 1
If rsTmp.EOF Then Exit For
rsTmp.MoveNext
Next count
Below line is not returing the value
objXLSheet.Cells(RowStart, ColumnStart) = " & rsTmp.Fields(" & i & ") &"
Please help me to correct this code...
-
Aug 5th, 2012, 04:40 AM
#2
Re: Extract the value only for few columns dynamically from result set
Below line is not returing the value
what is it returning?
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Aug 5th, 2012, 06:23 AM
#3
Thread Starter
Lively Member
Re: Extract the value only for few columns dynamically from result set
Hi Pete,
It's writing " & rsTmp.Fields(1) &" in the cell instead of value e.g. 2309 etc.
-
Aug 5th, 2012, 04:43 PM
#4
Re: Extract the value only for few columns dynamically from result set
try like
Code:
objXLSheet.Cells(RowStart, ColumnStart) = rsTmp.Fields( i)
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|