Results 1 to 8 of 8
  1. #1
    baba is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Nov 2011
    Posts
    43

    MsAccess Barchart Color Change using vba

    Hi All ,


    I have created a MS Access barchart by running a query. X axix has user name and y axis has counts. I would like to change every bar's color based on the x axis user name value .Is there a way to do that using vba code in MSAccess barcharts. Kindly advise.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,633
    Google: VBA Access barchart color

    Maybe this will help
    http://www.ozgrid.com/forum/showthread.php?t=147742
    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
    baba is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Nov 2011
    Posts
    43
    Hi ,
    Thanks for the details. The link you provided will work for excel but it is not working for MSAccess.
    I would like to know if I can read the values of x axis in a bargraph and change the color of each bar based on the value of x axis in MSACCESS.
    I appreciate your help !

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,633
    I have been able to adapt in Access VBA code concerning graphs that was written behind Excel. That said, I don't know if this particular case can be accomplished with Access graphing. Do you want to provide project for analysis?
    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.

  5. #5
    baba is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Nov 2011
    Posts
    43

    Barchart- concern

    Thanks for the response. I am writing a detailed explanation of my sceanrio below. Please see if you can help !

    Query ran to create barchart :Select jobname,count(*) from table 1;
    In my bargraph,
    X axix shows jobnames.
    Y axis shows counts.
    All the bars in barchart are of same color.

    Example bar 1 : jobname : Joba count 3
    Example bar 2 : jobname : Jobb Count 5
    Example bar 3 : jobname : Jobc count 7
    Example bar 4 :jobname : Joba count 7

    Currently the generated bar graph shows all jobs joba,jobb,jobc,jobd in the same color.
    My requirement:
    bar 1-Joba -Green -
    bar 2-Jobb -Blue
    bar 3-Jobc -Yellow
    bar 4-Job a -Green
    Is it possible to change the color of each barcode by reading the jobname of the bar that is in the x axis.



    Is it possible to write some code like this to change the bar colors after the bargraph is generated by my query....
    Step 1.Generate the bargraph by the query
    Step 2.Change the barcolor of each bar based on the jobname value .

    I have writtent the logic of what I want but I dont know the syntax and how to implement it .Kindly advise

    With Forms!Form2.Graph1
    For i = 1 to Forms!Form2.Graph1.SeriesCollection.Count
    If Forms!Form2.Graph1.SeriesCollection(i).Xaxis.value = "joba"
    then Forms!Form2.Graph1.SeriesCollection(i).interior.co lor = "Green"
    end if

    If Forms!Form2.Graph1.SeriesCollection(i).Xaxis.value = "jobb"
    then Forms!Form2.Graph1.SeriesCollection(i).interior.co lor = "Blue"
    end if

    If Forms!Form2.Graph1.SeriesCollection(i).Xaxis.value = "jobc"
    then Forms!Form2.Graph1.SeriesCollection(i).interior.co lor = "yellow"
    end if

    Next i

    End with
    Last edited by baba; 11-15-2011 at 11:46 AM. Reason: Providing more details

  6. #6
    baba is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Nov 2011
    Posts
    43

    Is this possible using barchart MS Access vba query

    SELECT TrendRemedytbl.[Job Name], Count(*) AS [Count]
    FROM TrendRemedytbl
    GROUP BY TrendRemedytbl.[Job Name];

    This query generates a barchart with jobname in xaxis and counts in yaxis .
    Can i also get the color of bar populated CORRECTLY based on if conditions within the query
    I want something like what I have pasted below but the syntax is incorrect. Please help ...

    SELECT iif TrendRemedytbl.[Job Name] = "A" THEN TrendRemedytbl.[Job Name] AS RED,iif TrendRemedytbl.[Job Name] = "B" THEN TrendRemedytbl.[Job Name] AS BLUE,iif TrendRemedytbl.[Job Name] = "C" THEN TrendRemedytbl.[Job Name] AS GREEN, Count(*) AS [Count]
    FROM TrendRemedytbl
    GROUP BY TrendRemedytbl.[Job Name];

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,633
    You need a nested IIf to set value:

    SELECT IIf([Job Name]="A","Red", IIf([Job Name]="B","BLUE", IIf([Job Name]="C","Green", "Black"))) AS NameColor, Count(*) AS NameCount
    FROM TrendRemedytbl
    GROUP BY [Job Name];

    Or use Switch function:
    SELECT Switch([Job Name]="A","Red", [Job Name]="B","BLUE", [Job Name]="C","Green") AS NameColor, Count(*) AS NameCount
    FROM TrendRemedytbl
    GROUP BY [Job Name];

    I have no idea how the bar chart will apply these values to color the bars.

    Found this code from a thread. I tested it in the Format event of a report and Open event of form. Both worked.
    Code:
    Private Sub Form_Open(Cancel As Integer) 
     
    With Me.Graph1
               .SeriesCollection(1).Interior.Color = RGB(255, 128, 128) 'peach
               .SeriesCollection(2).Interior.Color = RGB(0, 255, 128) 'green
               .SeriesCollection(3).Interior.Color = RGB(0, 128, 255) 'blue
               .SeriesCollection(4).Interior.Color = RGB(128, 255, 255) 'turquoise
               .SeriesCollection(5).Interior.Color = RGB(255, 255, 128) 'yellow
               .SeriesCollection(0).Interior.Color = RGB(255, 0, 255) 'magenta
    End With
     
    End Sub
    Last edited by June7; 11-15-2011 at 05:52 PM.
    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.

  8. #8
    baba is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Nov 2011
    Posts
    43
    Thanks .... Also this link works


    http://www.bigresource.com/Tracker/Track-ms_access-s7QD24x7/

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

Similar Threads

  1. Using an event to change color of text.
    By michaeljohnh in forum Programming
    Replies: 3
    Last Post: 08-30-2010, 12:30 PM
  2. Change Row Background Color Programmatically
    By sales@4bco.com in forum Programming
    Replies: 2
    Last Post: 10-25-2009, 11:17 AM
  3. Change as per condition font color
    By miziri in forum Programming
    Replies: 1
    Last Post: 08-20-2009, 04:23 AM
  4. Color/font change in subform
    By AndyKim in forum Forms
    Replies: 9
    Last Post: 06-24-2009, 04:34 PM
  5. change cell color
    By bishop743 in forum Programming
    Replies: 0
    Last Post: 02-01-2009, 11:00 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