Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old May 21st, 2005, 11:29 AM
wackyflik's Avatar
wackyflik wackyflik is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Location: Malaysia
Posts: 312 wackyflik User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 13 h 16 m 40 sec
Reputation Power: 4
Send a message via Yahoo to wackyflik
Numbering and count total data.

code below i found it from internet. it's ok and could run on my system where the data can be exported from the system in vb6 to ms excel. i want to make some adjustment in terms of numbering and total number of data. based on the original coding, the result in the ms excel does not show these two things. i have tried to edit the code, but still did not work. i would like to show the numbering at before the No Pelajar's cell and at the bottom of all records will show the total number of records. here is my the code. i do not completely understand at the Italic+Bold codes.

Code:
 
If Trim(cmbJbtn.Text) <> "" Then
		Screen.MousePointer = vbHourglass
		Connect ' function from Module1.bas
		Set ExlObj = CreateObject("excel.application")	 ' Initialize the excel object
		ExlObj.Workbooks.Add								' Add an excel workbook
		' Get the required data from the database
		rsGetAllData.Open "select P.pel_ID, P.pel_nama, T.tes_tajuk from " & _
				 "pelajar P, tesis T " & _
				 "where P.pel_ID = T.pel_ID " & _
				 "And P.pel_jabatan = '" + Trim(cmbJbtn.Text) + "'", con, adOpenDynamic, adLockOptimistic
		If Not rsGetAllData.EOF Then
		 ExlObj.Visible = True
		 With ExlObj.ActiveSheet
			' Print the heading and columns
			.Cells(1, 3).Value = "SENARAI NAMA DAN TAJUK TESIS. BAHAGIAN : " 
			 .Cells(1, 3).Font.name = "Verdana"
			 .Cells(1, 3).Font.Bold = True:	 .Cells(1, 5).Value = cmbJbtn.Text
			 .Cells(4, 1).Value = "No Pelajar": .Cells(4, 2).Value = "No Matrik"
			 .Cells(4, 3).Value = "Tajuk Tesis"
		 End With
		End If
		For k = 1 To rsGetAllData.Fields.Count
			 ExlObj.ActiveSheet.Cells(4, k).Font.Bold = True
		Next
		Set k = Nothing
		NxtLine = 5
		Do Until rsGetAllData.EOF
			For lc = 0 To rsGetAllData.Fields.Count - 1
				' Populate data into the sheet
				ExlObj.ActiveSheet.Cells(NxtLine, lc + 1).Value = rsGetAllData.Fields(lc)
				If rsGetAllData.Fields.Item(lc).Name <> "DATE" Then
				 ExlObj.ActiveSheet.Cells(NxtLine, lc + 1).Value = rsGetAllData.Fields(lc)
				Else
				 ExlObj.ActiveSheet.Cells(NxtLine, lc + 1).Value = Format(rsGetAllData.Fields(lc), "dd/mm/yy")
				End If
				' Autoformat the sheet
				ExlObj.ActiveCell.Worksheet.Cells(NxtLine, lc + 1).AutoFormat _
					 xlRangeAutoFormatList2, 0, regular, 3, 1, 1
			Next
			rsGetAllData.MoveNext
			NxtLine = NxtLine + 1
		Loop
		
		' Calculate the total
		ExlObj.ActiveCell.Worksheet.Cells(4, 1).Subtotal 4, xlSum, (6), 0, 0, xlSummaryBelow
		Screen.MousePointer = vbDefault
	Else
		MsgBox "Please select a code" & Chr(13) & "and then proceed"
		Screen.MousePointer = vbDefault
		Exit Sub
 



here is the original code.

Code:
 
On Error Resume Next
Dim lc, NxtLine, k
	If Trim(LstCode.Text) <> "" Then
		Screen.MousePointer = vbHourglass
		Connect
		Set ExlObj = CreateObject("excel.application")	 ' Initialize the excel object
		ExlObj.Workbooks.Add								' Add an excel workbook
		' Get the required data from the database
		rsGetAllData.Open "select ACCODE,CONTROL,TRNOS,DATE,TRCODE,AMOUNT,STAFFNOS from " & _
				 "TRPC0104 where TRCODE = '" + Trim(LstCode.Text) + "'", con, adOpenDynamic, adLockOptimistic
		If Not rsGetAllData.EOF Then
		 ExlObj.Visible = True
		 With ExlObj.ActiveSheet
			' Print the heading and columns
			.Cells(1, 3).Value = "VB TO EXCEL DEMO by Arun Banik"
			 .Cells(1, 3).Font.Name = "Verdana"
			 .Cells(1, 3).Font.Bold = True:
			 .Cells(4, 1).Value = "AC-Code":	.Cells(4, 2).Value = "Control"
			 .Cells(4, 3).Value = "TR-Nos":	 .Cells(4, 4).Value = "Date"
			 .Cells(4, 5).Value = "TR-Code":	.Cells(4, 6).Value = "Amount"
			 .Cells(4, 7).Value = "Staff Nos"
		 End With
		End If
		For k = 1 To rsGetAllData.Fields.Count
			 ExlObj.ActiveSheet.Cells(4, k).Font.Bold = True
		Next
		Set k = Nothing
		NxtLine = 5
		Do Until rsGetAllData.EOF
			For lc = 0 To rsGetAllData.Fields.Count - 1
				' Populate data into the sheet
				ExlObj.ActiveSheet.Cells(NxtLine, lc + 1).Value = rsGetAllData.Fields(lc)
				If rsGetAllData.Fields.Item(lc).Name <> "DATE" Then
				 ExlObj.ActiveSheet.Cells(NxtLine, lc + 1).Value = rsGetAllData.Fields(lc)
				Else
				 ExlObj.ActiveSheet.Cells(NxtLine, lc + 1).Value = Format(rsGetAllData.Fields(lc), "dd/mm/yy")
				End If
				' Autoformat the sheet
				ExlObj.ActiveCell.Worksheet.Cells(NxtLine, lc + 1).AutoFormat _
					 xlRangeAutoFormatList2, 0, regular, 3, 1, 1
			Next
			rsGetAllData.MoveNext
			NxtLine = NxtLine + 1
		Loop
 
		' Calculate the total
		ExlObj.ActiveCell.Worksheet.Cells(4, 1).Subtotal 4, xlSum, (6), 0, 0, xlSummaryBelow
		Screen.MousePointer = vbDefault
	Else
		MsgBox "Please select a code" & Chr(13) & "and then proceed"
		Screen.MousePointer = vbDefault
		Exit Sub
	End If
__________________
teach and correct me if i am wrong...

Last edited by wackyflik : May 21st, 2005 at 11:36 AM.

Reply With Quote
  #2  
Old May 22nd, 2005, 08:15 PM
Doug G Doug G is offline
Grumpier Old Moderator
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Sep 2003
Posts: 10,143 Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 21 h 28 m 48 sec
Reputation Power: 180
What do you mean by "did not work"?
__________________
======
Doug G
======
I didn't attend the funeral, but I sent a nice letter saying I approved of it. --Mark Twain

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > Numbering and count total data.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway