Results 1 to 3 of 3
  1. #1
    MFS is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2009
    Location
    Ohio
    Posts
    235

    How to "Scroll" through a Line Chart using Command Buttons

    I'm developing a query in my database for a line chart that will be on a form. What I would like is to be able to scroll through the chart by clicking command buttons forward and backwards. (Eventually another command button to query a date, but will get to that later)


    Example when opening the form the chart shows today's information, which is a trend of temperatures. I would like to review historical data by being able to push a command button showing data prior to what is being shown for today. And then be able to push another command button to scroll through the chart towards the latest information.
    Is this obtainable?

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    By line chart you mean a graph object on form? I supposed what you want can be accomplished, sounds like maybe code to modify the RowSource property of the graph and refresh the form. I have used VBA code to modify aspects of a graph and to refresh a graph on a form after record is saved. However, never tried changing the RowSource. Example:
    Code:
    Private Sub btnGraph_Click()
    SaveData
    Me.Refresh
    FormatGraph
    End Sub
    
    Sub SaveData()
    With Me
    If .tbxDUW1 <> "" Then !du1 = .tbxDUW1
    If .tbxDUW2 <> "" Then !du2 = .tbxDUW2
    If .tbxDUW3 <> "" Then !du3 = .tbxDUW3
    If .tbxDUW4 <> "" Then !du4 = .tbxDUW4
    If .tbxDUW5 <> "" Then !du5 = .tbxDUW5
    If .tbxMoisture1 <> "" Then !m1 = .tbxMoisture1
    If .tbxMoisture2 <> "" Then !m2 = .tbxMoisture2
    If .tbxMoisture3 <> "" Then !m3 = .tbxMoisture3
    If .tbxMoisture4 <> "" Then !m4 = .tbxMoisture4
    If .tbxMoisture5 <> "" Then !m5 = .tbxMoisture5
    If .tbxBulk <> "" Then !bulk = .tbxBulk
    If .tbxAbs <> "" Then !abs = .tbxAbs
    If .tbxSAS <> "" Then !appfine = .tbxSAS
    End With
    End Sub
    
    Sub FormatGraph()
    'format Proctor graph
    Dim dblDensity As Double
    Dim dblMoisture As Double
    With Me
        dblMoisture = Nz(!omc, 0)
        dblDensity = Nz(!mdd, 0)
        If dblMoisture > 0 And dblDensity > 0 Then
            With .gphDensity
            'format y axis scale
            If .Parent!Metric = True Then
                dblDensity = Int(dblDensity / 10) * 10 + 50
                .Axes(xlValue).MaximumScale = dblDensity
                .Axes(xlValue).MinimumScale = dblDensity - 250
                .Axes(xlValue).MajorUnit = 50
                .Axes(xlValue).MinorUnit = 10
            Else
                dblDensity = Int(dblDensity) + 2 + IIf(dblDensity - Int(dblDensity) > 0, 1, 0)
                .Axes(xlValue).MaximumScale = dblDensity
                .Axes(xlValue).MinimumScale = dblDensity - 10
                .Axes(xlValue).MajorUnit = 2
                .Axes(xlValue).MinorUnit = 0.4
            End If
            'format x axis scale
            If Int(dblMoisture) > 6 Then
                dblMoisture = IIf(dblMoisture - Int(dblMoisture) > 5, RRound(dblMoisture, 0), Int(dblMoisture))
                .Axes(xlCategory).MaximumScale = dblMoisture + 5
                .Axes(xlCategory).MinimumScale = dblMoisture - 7
                .Axes(xlCategory).MajorUnit = 2
                .Axes(xlCategory).MinorUnit = 0.4
            End If
            'y axis label
            .Axes(xlValue, xlPrimary).HasTitle = True
            If .Parent!Metric = True Then
                .Axes(xlValue, xlPrimary).AxisTitle.Text = "Dry Density, kg/cu.m"
            End If
            .Visible = True
            End With
        End If
    End With
    End Sub
    If you want a "Next" button will probably need a textbox to keep track of the date criteria incremented by the code and refer to that textbox as a parameter in the graph RowSource SQL.

    In your case, might be like:
    Private Sub btnGraphNext_Click()
    Me.textbox = Me.textbox + 1
    Me.Refresh
    End Sub
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    MFS is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2009
    Location
    Ohio
    Posts
    235
    Thanks June7, This looks to be a good start in the right direction or at least something I can try working with.
    I'm out of the office for a few days, when I return and have the time to try this I will inform you and the forum with the results.
    Thanks again,

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 30
    Last Post: 09-27-2013, 01:34 PM
  2. Replies: 3
    Last Post: 06-09-2012, 08:14 AM
  3. "Not" criteria works for one line, but not two
    By avarusbrightfyre in forum Queries
    Replies: 1
    Last Post: 02-02-2012, 10:56 AM
  4. Replies: 5
    Last Post: 12-06-2010, 10:15 AM
  5. Replies: 1
    Last Post: 10-19-2009, 02:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums