|
Question : Graphing in Microsoft Access
|
|
Hi,
I'm trying to create graphs in microsoft access. My access front end connects to a SQL server back end. I will be creating a simple scatter plot graph with [name] as the plots with associated x, y coordinates. But i want to be able to filter out certain data by writing specific queries to the database like:
select name, x, y from data where criteria1=... and criteria2=...
Is there a way to script out the properties of a graph in VB then pass it this query and generate a dynamic graph? I know that there are countless graphing packages out there but I'm trying to utilize what Microsoft Office has to offer first.
|
|
Answer : Graphing in Microsoft Access
|
|
For what it's worth... this is what I typically do in Access when trying to accomplish such a task.
I will create a table where I will store all my final data that I want to export to Excel to graph.
In a button click event: I'll delete the contents of the table mentioned above. I'll run a series of queries and code to filter the data and re-populate my table with the data desired. I'll then export the newly populated table to Excel by doing something like:
Function ExportToExcel(intTireID As Integer) As Boolean Dim objXL As Excel.Application Dim objWkb As Excel.Workbook Dim objSht As Excel.Worksheet Dim intLastCol As Integer Dim strMAX As Integer Dim strSHT_NAME As String Dim strWKB_NAME As String
Dim rstLoad As Recordset Dim strPath As String, strSource As String Dim intTubeID As Integer
Set rstLoad = CurrentDb.OpenRecordset("tblLoadSingle")
strPath = "C:\Wherever\MyDataSheet.xls"
'COPY Original strSource = strPath & "\BASE_SHEET\BLANK.xls" strPath = strPath & "\" & rstTire!MSPN & ".xls" FileCopy strSource, strPath '***************************************
'*************************************** strSHT_NAME = "Sheet1" strWKB_NAME = strPath Set objXL = New Excel.Application
With objXL .Visible = True Set objWkb = .Workbooks.Open(strWKB_NAME) Set objSht = objWkb.Worksheets(strSHT_NAME) With objSht 'LOAD 'COLUMN A If Len(rstLoad!MPH1) > 0 Then .Range("A7").Value = rstLoad!MPH1 & " mph" If Len(rstLoad!KMH1) > 0 Then .Range("A8").Value = rstLoad!KMH1 & " km/h" If Len(rstLoad!LoadLBS1a) > 0 Then .Range("A9").Value = rstLoad!LoadLBS1a & " lbs" If Len(rstLoad!LoadKGS1a) > 0 Then .Range("A10").Value = rstLoad!LoadKGS1a & " kgs" If Len(rstLoad!LoadLBS1b) > 0 Then .Range("A11").Value = rstLoad!LoadLBS1b & " lbs" If Len(rstLoad!LoadKGS1b) > 0 Then .Range("A12").Value = rstLoad!LoadKGS1b & " kgs" 'COLUMN B If Len(rstLoad!MPH2) > 0 Then .Range("B7").Value = rstLoad!MPH2 & " mph" If Len(rstLoad!KMH2) > 0 Then .Range("B8").Value = rstLoad!KMH2 & " km/h" If Len(rstLoad!LoadLBS2a) > 0 Then .Range("B9").Value = rstLoad!LoadLBS2a & " lbs" If Len(rstLoad!LoadKGS2a) > 0 Then .Range("B10").Value = rstLoad!LoadKGS2a & " kgs" If Len(rstLoad!LoadLBS2b) > 0 Then .Range("B11").Value = rstLoad!LoadLBS2b & " lbs" If Len(rstLoad!LoadKGS2b) > 0 Then .Range("B12").Value = rstLoad!LoadKGS2b & " kgs"
'COLUMN C If Len(rstLoad!MPH3) > 0 Then .Range("C7").Value = rstLoad!MPH1 & " mph" If Len(rstLoad!KMH3) > 0 Then .Range("C8").Value = rstLoad!KMH1 & " km/h" If Len(rstLoad!LoadLBS3a) > 0 Then .Range("C9").Value = rstLoad!LoadLBS3a & " lbs" If Len(rstLoad!LoadKGS3a) > 0 Then .Range("C10").Value = rstLoad!LoadKGS3a & " kgs" If Len(rstLoad!LoadLBS3b) > 0 Then .Range("C11").Value = rstLoad!LoadLBS3b & " lbs" If Len(rstLoad!LoadKGS3b) > 0 Then .Range("C12").Value = rstLoad!LoadKGS3b & " kgs"
'PRESSURE If Len(rstLoad!PressurePSIa) > 0 Then .Range("G9").Value = rstLoad!PressurePSIa & " psi" If Len(rstLoad!PressureBara) > 0 Then .Range("G10").Value = rstLoad!PressureBara & " bar" If Len(rstLoad!PressurePSIb) > 0 Then .Range("G11").Value = rstLoad!PressurePSIb & " psi" If Len(rstLoad!PressureBarb) > 0 Then .Range("G12").Value = rstLoad!PressureBarb & " bar"
End With End With Set objSht = Nothing Set objWkb = Nothing Set objXL = Nothing
End Function
THERE are many examples on this site of how to export to excel.. In the above, I make a copy of a worksheet because I create a worksheet with my graph based on fixed cells and I don't want to muck up my original.
Good Luck!!
|
|
|
|