Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Impossible to capture Mouse_up in bound Excel Chart?

Status
Not open for further replies.

iamareplicant

Programmer
Aug 7, 2004
50
US
I have an Access app that has a bound control tied to an Excel chart in a workbook.

Here is code that is in the Excel chart that captures the user's click event on a histogram:

Code:
Public Sub Chart_MouseUp(ByVal Button As Long, ByVal Shift As Long, ByVal x As Long, ByVal y As Long)
 Dim ElementID As Long, Arg1 As Long, Arg2 As Long
 Dim myX As Variant, myY As Double

 With ActiveChart
 .GetChartElement x, y, ElementID, Arg1, Arg2
 If ElementID = xlSeries Or ElementID = xlDataLabel Then
 If Arg2 > 0 Then
 myX = WorksheetFunction.Index(.SeriesCollection(Arg1).XValues, Arg2)
 myY = WorksheetFunction.Index(.SeriesCollection(Arg1).Values, Arg2)
‘ g_strClickedVal = myX
‘ frmValue.Show
 End If
 End If
 End With
End Sub

OK, what I would like to be able to do (and I dont know if it is even possible) is to have this exact same functionality within my Access bound control where this chart is displayed.

Here is code that cannot ever run, but depicts the essence what I would like to have happen:

Code:
Private Sub ole0A_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    
    Dim ElementID As Long, Arg1 As Long, Arg2 As Long
    Dim myX As Variant, myY As Double
    Dim objExcelApp As Excel.Application
    Dim objExcelWB As Excel.Workbook
    Dim objExcelChart As Excel.Chart
    Dim objExcelSheet As Excel.Worksheet
    Dim objExcelSheet2 As Excel.Worksheet
    Dim objCH As Excel.ChartObject
    Dim objChart As Object
        
        Set objExcelApp = CreateObject("Excel.Application")
        objExcelApp.Visible = False
        Set objExcelWB = objExcelApp.Workbooks.Open _
                            (GetSpecialfolder(CSIDL_DESKTOP) & "\ACT Excel\" & Me.cboMain0 & ".xls")
        Set objExcelChart = objExcelWB.Charts(Me.cboMain0 & "CHART")
        Set objExcelSheet = objExcelWB.Sheets("Sheet1")
        Set objCH = objExcelSheet.ChartObjects(1)
        Set objExcelChart = objCH.Chart
        
        Set objExcelChart = ole0A.Object
        
        'ole0A.Object
        With objChart
            .GetChartElement X, Y, ElementID, Arg1, Arg2
            If ElementID = xlSeries Or ElementID = xlDataLabel Then
                If Arg2 > 0 Then
                    myX = WorksheetFunction.Index(.SeriesCollection(Arg1).XValues, Arg2)
                    myY = WorksheetFunction.Index(.SeriesCollection(Arg1).Values, Arg2)
                    'g_strClickedVal = myX
                    'frmValue.Show
                    MsgBox myX
                End If
            End If
        End With
        Set objExcelChart = Nothing
        Set objExcelWB = Nothing
        objExcelApp.Quit
        Set objExcelApp = Nothing
End Sub

There ya have it. Any help in how to get the chart within my bound Access control to behave as it does in its native/Excel environment would be much appreciated. Or, if you know, let me know that it is impossible.

TIA

JBG
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top