An investment in knowledge
pays the best interest.
-Benjamin Franklin
 
Home   News   Tips   Glossary   Templates   Forums   Help   Logon   Order   Contact Us  
 
Tips & Tricks

New Tips Added Weekly!
Click here to get on our Mailing List

   
 
HTA

Advanced - Using Google Charts

Google Charts

Google Chart

Please not this technique is using a Deprecated method so may not work. Info

It would be useful to have completed the Access course first. I will assume this and not go through it.

We are going to use the sample PCResale.NET Db from the Access Courses.


	'https://developers.google.com/chart/image/docs/chart_params#gcharts_chs
	chtt=<chart_title>
	chts=<color>,<font_size>,<opt_alignment>
	chs=<width>x<height>
	chf=<fill_type>,s,<color>
	cht=<chart_type>
	chd=t:s,e,r,i,e,s,1|s,e,r,i,e,s,2|...  OR  s:series1,series2,...  OR  e:series1,series2,...
	chl=<label>|...
	
Final
	<script language="vbscript">
	' Connection String
	Dim sConnect
	'Commands
	Dim objCmdPC 'Pie Chart
	 
	'RecordSets
	Dim objRSPC
	 
	'Initialize Connection String to connect to an MS Access Database
	sConnect = "Provider=Microsoft.Ace.OLEDB.12.0;Data Source=PCResale.accdb;
		Persist Security Info=False"
	 
	Sub CreateChart()
	 
		'Create a command object to execute Advancded SQL Statements
		Set objCmdPC = CreateObject("ADODB.Command")
		objCmdPC.ActiveConnection = sConnect    'Connect to database
	 
		' Total Number Customers in a Company
		objCmdPC.CommandText = "SELECT CustomerT.CompanyName, 
			Count(CustomerT.CompanyName) AS CountOfCompanyName 
			FROM CustomerT GROUP BY CustomerT.CompanyName;"
	 
		' Create the actual recordset to be used in this script 
		' and retrieve or display information from database
		Set objRSPC = CreateObject("ADODB.Recordset")
		Set objRSPC = objCmdPC.Execute
		 
		Dim strPC
		Dim chartTitle
		Dim chartValues
		Dim chartLabels
		Dim chartColours
		 
		Dim chtType
	 
		Dim n
		For n = 0 to Document.Charts.chtType.length - 1
			If Document.Charts.chtType(n).checked Then
				chtType = Document.Charts.chtType(n).Value
			End If
		Next
		 
		While Not objRSPC.EOF
			chartLabels = chartLabels & objRSPC("CompanyName") &_
				" (" & objRSPC("CountOfCompanyName") & ")" & "|"
			chartValues = chartValues & objRSPC("CountOfCompanyName") & ","
			objRSPC.MoveNext
		Wend
		 
		chartLabels = Left(chartLabels, len(chartLabels)-1)
		chartValues = Left(chartValues, len(chartValues)-1)
		 
		chartTitle = "Number of Customers in a Company"
		 
		'https://developers.google.com/chart/image/docs/chart_params#gcharts_chs
		'chtt=<chart_title>
		'chts=<color>,<font_size>,<opt_alignment>
		'chs=<width>x<height>
		'chf=<fill_type>,s,<color>
		'cht=<chart_type>
		'chd=t:s,e,r,i,e,s,1|s,e,r,i,e,s,2|...  OR  s:series1,series2,...  OR  e:series1,series2,...
		'chl=<label>|...
		 
		strPC = "<img src='http://chart.apis.google.com/chart?" &_
					"chtt=" & chartTitle & "&" &_
					"chts=000000,12&" &_
					"chs=450x150&" &_
					"chf=bg,s,ffffff&" &_
					"cht=" & chtType & "&" &_
					"chd=t:" & chartValues & "&" &_
					"chl=" & chartLabels & "&" &_
					"chco=FFCC00,33CC00,3333FF,CC0000' " &_
					"alt='" & chartTitle & "'/>"
	 
		'msgbox strPC
		document.Charts.source.value = strPC
		myContent.innerHTML = strPC
		 
		'Clean Up and Close
		objRSPC.Close
		Set objRSPC = Nothing
	 
	End Sub
	</script>
	
	<!DOCTYPE html>
	<html lang="en">
	<head>
	   <title>Using a Google Chart</title>
		
	   <HTA:APPLICATION
			APPLICATIONNAME = "Google Chart"
			ICON = "599CD.ico"
		/>

		<script language="vbscript">
		</script>
	</head>
	<body>
     
    <h1>Google Charts</h1>
    <form name="Charts" method="post" action="GoogleChart.hta">
	
		<input type="button" value="Chart" OnClick="CreateChart()">
		<input type="radio" name="chtType" value="p"> Flat
		<input type="radio" name="chtType" value="p3" checked="checked"> Angled
		
		<br />
		<input type="text" name="source" id="source" size="100">

		</form>
		
		<h2>Results</h2>
		<div id="myContent">
		</div>
		
	</body>
	</html>
	

GoogleChart HTA


Sample Files
GoogleChart.hta
PCResale.accdb


Index: Index | Lesson: Connect to an Access db

 

Alex Hedley (Avatar) By: Alex Hedley


Click here to sign up for more FREE tips

 

 

Learn
 
Accessindex
Excelindex
Wordindex
Windowsindex
PowerPointindex
Photoshopindex
Visual Basicindex
ASPindex
Seminars
More...
Customers
 
Account Login
Online Theater
Downloads
Lost Password
Free Upgrades
Insider Circle
Student Databases
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Articles
Search Our Site
Waiting List
Production Schedule
Collapse Menus
Help
 
Live Chat
Customer Support
WalkThru Tutorials
Troubleshooting
FAQs
TechHelp
Consulting Services
About Us
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
Order
 
Video Tutorials
Handbooks
MYOLP Memberships
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Gift CDs
Contact
 
Live Chat
General Info
Support Policy
Contact Form
Email Us
Mailing Address
Phone Number
Fax Number
Course Survey
Facebook    Twitter

Google Plus    LinkedIn

Blog RSS Feed    YouTube Channel
Richard Rost Microsoft MVP