PC Review


Reply
Thread Tools Rate Thread

Avoid protected cell warning on BeforeDoubleClick WS event

 
 
Matt
Guest
Posts: n/a
 
      15th Apr 2010
I am creating an event scheduling worksheet. A grid is generated with days
of the month x-axis and users y-axis. Where an event occurs this is logged
by a hidden event ID in the appropriate day cell. In order to prevent this
ID from being overwritten I protect the worksheet. What I am trying to do is
have a worksheet DoubleClick event which either.

1) Captures the event ID in the underlying cell, and opens a custom form for
editing the event, or
2) Recognises that no event exists and opens a custom form for logging a new
event.

What I have tried is to unprotect the worksheet at the start of my procedure
and then protect it following the code

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)
Dim lActiveColumn As Long, lActiveDay As Long
Dim dActiveMonthDate As Date
ActiveSheet.Unprotect
lActiveColumn = Target.Column
lActiveDay = Cells(4, lActiveColumn).Value
dActiveMonthDate = Cells(1, (lActiveColumn - (lActiveDay - 1))).Value
If Target.Value = 0 Then
MsgBox ("DATE:" & lActiveDay & "/" & Month(dActiveMonthDate) & "/" &
Year(dActiveMonthDate))
Else
MsgBox ("EVENT ID: " & Target.Value)
End If
ActiveSheet.Protect
End Sub

But the warning message still appears.

Is there a method of disabling this warning message temporarily, or is there
another method which may be more suitable?, I considered BeforeRightClick
but this results in the context menu appearing after the code has executed.

Any advice and/or alternative solutions appreciated

Thanks in advance
Matt



 
Reply With Quote
 
 
 
 
JLatham
Guest
Posts: n/a
 
      15th Apr 2010
The short answer is to put
Cancel = True
into which ever part of the If..Then...Else statement you want to execute
and ignore the double-click. If you just want to ignore the double-click
regardless, then just put that statement pretty much anywhere outside of the
If...Then...Else block.


"Matt" wrote:

> I am creating an event scheduling worksheet. A grid is generated with days
> of the month x-axis and users y-axis. Where an event occurs this is logged
> by a hidden event ID in the appropriate day cell. In order to prevent this
> ID from being overwritten I protect the worksheet. What I am trying to do is
> have a worksheet DoubleClick event which either.
>
> 1) Captures the event ID in the underlying cell, and opens a custom form for
> editing the event, or
> 2) Recognises that no event exists and opens a custom form for logging a new
> event.
>
> What I have tried is to unprotect the worksheet at the start of my procedure
> and then protect it following the code
>
> Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
> Boolean)
> Dim lActiveColumn As Long, lActiveDay As Long
> Dim dActiveMonthDate As Date
> ActiveSheet.Unprotect
> lActiveColumn = Target.Column
> lActiveDay = Cells(4, lActiveColumn).Value
> dActiveMonthDate = Cells(1, (lActiveColumn - (lActiveDay - 1))).Value
> If Target.Value = 0 Then
> MsgBox ("DATE:" & lActiveDay & "/" & Month(dActiveMonthDate) & "/" &
> Year(dActiveMonthDate))
> Else
> MsgBox ("EVENT ID: " & Target.Value)
> End If
> ActiveSheet.Protect
> End Sub
>
> But the warning message still appears.
>
> Is there a method of disabling this warning message temporarily, or is there
> another method which may be more suitable?, I considered BeforeRightClick
> but this results in the context menu appearing after the code has executed.
>
> Any advice and/or alternative solutions appreciated
>
> Thanks in advance
> Matt
>
>
>

 
Reply With Quote
 
Matt
Guest
Posts: n/a
 
      15th Apr 2010
Thanks, works a treat

"JLatham" <(E-Mail Removed)> wrote in message
news:E0AA30DE-002C-4F92-89DA-(E-Mail Removed)...
> The short answer is to put
> Cancel = True
> into which ever part of the If..Then...Else statement you want to execute
> and ignore the double-click. If you just want to ignore the double-click
> regardless, then just put that statement pretty much anywhere outside of
> the
> If...Then...Else block.
>
>
> "Matt" wrote:
>
>> I am creating an event scheduling worksheet. A grid is generated with
>> days
>> of the month x-axis and users y-axis. Where an event occurs this is
>> logged
>> by a hidden event ID in the appropriate day cell. In order to prevent
>> this
>> ID from being overwritten I protect the worksheet. What I am trying to do
>> is
>> have a worksheet DoubleClick event which either.
>>
>> 1) Captures the event ID in the underlying cell, and opens a custom form
>> for
>> editing the event, or
>> 2) Recognises that no event exists and opens a custom form for logging a
>> new
>> event.
>>
>> What I have tried is to unprotect the worksheet at the start of my
>> procedure
>> and then protect it following the code
>>
>> Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
>> Boolean)
>> Dim lActiveColumn As Long, lActiveDay As Long
>> Dim dActiveMonthDate As Date
>> ActiveSheet.Unprotect
>> lActiveColumn = Target.Column
>> lActiveDay = Cells(4, lActiveColumn).Value
>> dActiveMonthDate = Cells(1, (lActiveColumn - (lActiveDay - 1))).Value
>> If Target.Value = 0 Then
>> MsgBox ("DATE:" & lActiveDay & "/" & Month(dActiveMonthDate) & "/" &
>> Year(dActiveMonthDate))
>> Else
>> MsgBox ("EVENT ID: " & Target.Value)
>> End If
>> ActiveSheet.Protect
>> End Sub
>>
>> But the warning message still appears.
>>
>> Is there a method of disabling this warning message temporarily, or is
>> there
>> another method which may be more suitable?, I considered BeforeRightClick
>> but this results in the context menu appearing after the code has
>> executed.
>>
>> Any advice and/or alternative solutions appreciated
>>
>> Thanks in advance
>> Matt
>>
>>
>>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
BeforeDoubleClick Event not working Ayo Microsoft Excel Programming 2 10th Mar 2010 07:21 PM
BeforeDoubleClick on Protected Sheet Paul Microsoft Excel Programming 2 8th Oct 2009 10:44 AM
Avoid security warning through VBA shailesh.tewari@gmail.com Microsoft Access 2 14th Sep 2006 08:02 AM
How to avoid execution of page_load event before click event of a =?Utf-8?B?Sm9zZVZhbGVuY2lh?= Microsoft ASP .NET 5 4th Apr 2006 12:00 PM
Replace a warning message...on protected cell mika Microsoft Excel Programming 3 12th Aug 2004 01:30 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:39 PM.