Print Page | Close Window

ChangeEvent

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Calendar
Forum Description: Topics Related to Codejock Calendar
URL: http://forum.codejock.com/forum_posts.asp?TID=4946
Printed Date: 22 November 2024 at 3:30pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: ChangeEvent
Posted By: tomgriff
Subject: ChangeEvent
Date Posted: 01 September 2006 at 2:49am
Hello,
 
I need to update a customProperty in an event if a user drags an event on the calendar. 
 
This fires the EventChange,  after I update the CustomProperty with the new data, I do the DataProvider.ChangeEvent pEvent method. 
 

If MsgBox("Are you sure you want to Re-Schedule this Appointment?", vbCritical + vbYesNoCancel) = vbYes Then
  Dim pEvent As CalendarEvent
  Set pEvent = calCalendar.DataProvider.GetEvent(EventID)
 
  Dim sSql As String
  Dim rsUpdate As New adodb.Recordset
 
  Dim retvar
  Dim iApptID As Integer
  Dim lngClientID As Long
 
  ' pEvent Is Nothing for recurrence Ocurrence and Exception.
  ' See CalendarControl_PatternChanged for recurrence events changes.
  If Not pEvent Is Nothing Then
  
    iApptID = Val(NZ(pEvent.CustomProperties("apptid"), 0))
    lngClientID = Val(NZ(pEvent.CustomProperties("clientid"), 0))
    retvar = goADO.ExecuteSQL("UPDATE tblDataClientApptDate SET Reschedule = True Where ApptID = " & iApptID)
   
    ' Now I need to build a new tblDataClientApptDate item for the rescheduled appointment.
    ' I need the new ApptID for the new Item, and I need to put the new apptID into the Customer Property of the event.
    iApptID = NZ(CLng(NZ(VLookup("Max([ApptID]) AS NextID", GetDBName(), "tblDataClientApptDate"), 0)) + 1)
    pEvent.CustomProperties("ApptID") = iApptID
    calCalendar.DataProvider.ChangeEvent pEvent
 
This puts me into a loop. 
 
Am I doing this at the wrong place or is there an excepted way to get out of the loop.
 
 



Replies:
Posted By: sserge
Date Posted: 01 September 2006 at 4:04pm
Hi,

Actually this is quite often case - when from some event handler you call method which fires this event again and you get a loop and stack overflow.
 
The idea to avoid this is to have a global semaphore of running this method, as following:

Dim g_bChangeEventRunning as Boolean
 
sub Form_Load()
    g_bChangeEventRunning = False
end sub
 
sub wndCalendar_EventChanged(......)
    OnErrOr GoTo mExit:
 
    if g_bChangeEventRunning then
        Exit sub
    end if
   
    g_bChangeEventRunning = True
   
    '------------------
    ' place your code here
    '------------------

mExit:
    g_bChangeEventRunning = False 'ensure that you reset this to false before exit this sub
 
end sub


--
WBR,
Serge


Posted By: tomgriff
Date Posted: 10 September 2006 at 5:09pm
Thanks for the reply. I will give this a try.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net