Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Why does the click event get control?

I have the following code in the workbook_open event
Private Sub Workbook_Open()
On Error GoTo errhand
ActiveWorkbook.Sheets(1).Select
ActiveSheet.Codes.Width = 200
ActiveSheet.Codes.ColumnCount = 2
ActiveSheet.Codes.BoundColumn = 2
ActiveSheet.Codes.ColumnWidths = "2 IN;.5IN"
ActiveSheet.Codes.TextColumn = 1
ActiveSheet.Codes.ListFillRange = "=Codes"
ActiveSheet.Codes.Visible = False
Exit Sub
errhand: MsgBox "Error Number is " & Err.Number & " Error Description is " &
Err.Description
End Sub

When the Codes "BoundColumn" Statement is executed, control passes to the
Codes_Click Event. Codes is a combo box on sheet 1

Why does this happen? How do I set the BoundCOlumn without giving up control?

TIA
Lee Hunter
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default Why does the click event get control?

Hi Lee,

Your code is triggering the Click event (it triggered the Change event in my
testing, but nonetheless), which you ascertained. To stop this from
happening, you can use a global Boolean variable to track whether you want
event code to "run" or not. Add this to a public module:

Public gbDisableEvents

Now, in your code:

Private Sub Workbook_Open()
On Error GoTo errhand
gbDisableEvents = True
ActiveWorkbook.Sheets(1).Select
ActiveSheet.Codes.Width = 200
ActiveSheet.Codes.ColumnCount = 2
ActiveSheet.Codes.BoundColumn = 2
ActiveSheet.Codes.ColumnWidths = "2 IN;.5IN"
ActiveSheet.Codes.TextColumn = 1
ActiveSheet.Codes.ListFillRange = "=Codes"
ActiveSheet.Codes.Visible = False
ExitRoutine:
gbDisableEvents = False
Exit Sub
errhand: MsgBox "Error Number is " & Err.Number & " Error Description is " &
_
Err.Description
Resume ExitRoutine
End Sub

Now, in your event handlers, just do this:

Private Sub Codes_Click()
If Not gbDisableEvents Then
'/ your code
End If
End Sub

--
Regards,

Jake Marx
www.longhead.com


[please keep replies in the newsgroup - email address unmonitored]

Lee Hunter wrote:
I have the following code in the workbook_open event
Private Sub Workbook_Open()
On Error GoTo errhand
ActiveWorkbook.Sheets(1).Select
ActiveSheet.Codes.Width = 200
ActiveSheet.Codes.ColumnCount = 2
ActiveSheet.Codes.BoundColumn = 2
ActiveSheet.Codes.ColumnWidths = "2 IN;.5IN"
ActiveSheet.Codes.TextColumn = 1
ActiveSheet.Codes.ListFillRange = "=Codes"
ActiveSheet.Codes.Visible = False
Exit Sub
errhand: MsgBox "Error Number is " & Err.Number & " Error Description
is " & Err.Description
End Sub

When the Codes "BoundColumn" Statement is executed, control passes to
the Codes_Click Event. Codes is a combo box on sheet 1

Why does this happen? How do I set the BoundCOlumn without giving up
control?

TIA
Lee Hunter



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
call a function on control click event tkraju via OfficeKB.com Excel Discussion (Misc queries) 7 August 25th 06 07:22 AM
Click event to run only once gavmer[_85_] Excel Programming 0 October 5th 04 12:18 AM
Click event to run only once gavmer[_82_] Excel Programming 1 September 30th 04 12:42 PM
On Click Event?, and how to use Wandering Mage Excel Programming 5 June 7th 04 04:28 PM
VBA- Calendar Control Click Event W Specific Select Case requirements Mark[_23_] Excel Programming 0 September 12th 03 06:24 PM


All times are GMT +1. The time now is 04:18 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"