SOLVED: Event ID |
Post Reply |
Author | |
JasonG
Groupie Joined: 07 July 2008 Status: Offline Points: 76 |
Post Options
Thanks(0)
Posted: 21 July 2008 at 10:03am |
I am manually populating a Calendar from a SQL Database. I want to Assign each event's ID based on the ID in the database, so when an Item is clicked, I know right away which database record is going to be affected. However, the ID does not seem to be writable.
There is no Event.Tag property I can see, or anything along that line. The catch Is that I want to be able to use the .GetEvent property to quickly see if the event already exists. Please advise as to what is the best way to accomplish this. UPDATE: I've also tried to use the CustomProperties collection, but when I goto to edit an event, I get an error "Object is no longer Valid" Private Sub Calendar1_EventChangedEx(ByVal pEvent As XtremeCalendarControl.CalendarEvent) Dim SQL As String SQL = "Update CalendarEvents Set " & _ "StartTime='" & pEvent.StartTime & "', " & _ "EndTime='" & pEvent.EndTime & "', " & _ "EventTitle='" & pEvent.Subject & "' " & _ "Where EventID=" & pEvent.CustomProperties.Property("eventid").Value Conn.Execute SQL End Sub |
|
Product: Xtreme SuitePro (ActiveX) 12.0.1
Platform: Windows Vista/XP Language: Visual Basic 6.0 SP6 |
|
StephenMurphy
Newbie Joined: 13 July 2008 Location: Canada Status: Offline Points: 8 |
Post Options
Thanks(0)
|
I am doing very similar in my app. Data is stored in the Events table in an mdb file. I wanted to use the RECORD_ID from the mdb file and make it the same for the Calendar event.
I set up as a custom provider in my Form open event: Me.CalendarControl0.SetDataProvider "Provider=Custom" Me.CalendarControl0.DataProvider.Open and then responded to the DoRetrieveDayEvents event as follows: Private Sub CalendarControl0_DoRetrieveDayEvents(ByVal dtDay As Date, ByVal Events As Object) Dim oEvent As CalendarEvent Dim sQuery As String Dim db As Database, SourceSet As Recordset sQuery = "SELECT * FROM Events WHERE EVENT_DATE = #" & dtDay & "#);" Set db = CurrentDb Set SourceSet = db.OpenRecordset(sQuery, DB_OPEN_DYNASET) ' no events found If SourceSet.BOF Then SourceSet.Close Exit Sub End If SourceSet.MoveFirst Do Set oEvent = Me.CalendarControl0.DataProvider.CreateEventEx(SourceSet("RECORD_ID")) oEvent.StartTime = SourceSet!EVENT_START oEvent.EndTime = SourceSet!EVENT_END oEvent.Location = SourceSet!FACILITY_NAME oEvent.Label = SourceSet!COLOR_INDEX 'etc Events.Add oEvent SourceSet.MoveNext Loop While Not SourceSet.EOF SourceSet.Close End Sub The CreateEventEx(ID) function will return you a new event object with your desired ID as the Event ID. You can then use the code: Dim oDP As CalendarDataProvider Set oDP = Me.CalendarControl0.DataProvider ' find event or create it Set oEvent = oDP.GetEvent(lFindThisID) If oEvent Is Nothing Then Set oEvent = oDP.CreateEventEx(lFindThisID) End If ' use oEvent...... |
|
JasonG
Groupie Joined: 07 July 2008 Status: Offline Points: 76 |
Post Options
Thanks(0)
|
Thank you, that is a great solution!
The problem I have now, is the when a user double clicks the calendar to create an event, and AddEventEx is called, how do I now re-assign that new EventID to the already created 'pEvent'? Private Sub Calendar1_EventAddedEx(ByVal pEvent As XtremeCalendarControl.CalendarEvent) If Not CalendarEventAddedFromDB Then pEvent.Id = AddEventToDatabase(pEvent) End If End Sub Function AddEventToDatabase(ByVal pEvent As XtremeCalendarControl.CalendarEvent) As Long 'Returns eventID of newly created event Dim r As Recordset Set r = OpenRS("AddCalendarEvent '" & pEvent.StartTime & "', '" & pEvent.EndTime & "', " & UserID & ", '" & Replace(pEvent.Subject, "'", "''") & "', '" & Replace(pEvent.location, "'", "''") & "', '" & Replace(pEvent.body, "'", "''") & "'") AddEventToDatabase = r.Fields(0) End Function |
|
Product: Xtreme SuitePro (ActiveX) 12.0.1
Platform: Windows Vista/XP Language: Visual Basic 6.0 SP6 |
|
StephenMurphy
Newbie Joined: 13 July 2008 Location: Canada Status: Offline Points: 8 |
Post Options
Thanks(0)
|
In my app, I never let the user alter the Calendar info directly, so I don't have to worry about moving data from the Calendar to the data file. Only from the data file to the Calendar. I do this by intercepting the mouse clicks and bringing up my own forms which are interacting directly with the database. After that is done I update the Calendar event accordingly. Some pared down code:
Private Sub CalendarControl0_DblClick() Dim HitTest As CalendarHitTestInfo Dim bRet As Boolean Dim vDate As Date Dim lID as Long Set HitTest = Me.CalendarControl0.ActiveView.HitTest If HitTest.ViewEvent Is Nothing Then ' clicked on day rather than event... vDate = Format(HitTest.HitDateTime, "m/d/yy") ' check for valid date and make sure user wasn't clicking outside of calendar, etc ' show my own event form in add mode and get back a new ID from mdb lID = ShowAddEventForm(vDate) 'show event form in add mode If lID <> 0 Then AddItemToCalendar(lID) ' calls CreateEventEx(lID) and fills in event details End If Else ' user clicked on event, show my form ShowMyEventForm(HitTest.ViewEvent.Event.ID) ' copy changes to calendar event bRet = CopyItemToCalendarEvent(HitTest.ViewEvent.Event.ID, HitTest.ViewEvent.Event) If bRet = True Then 'it was altered and should be updated Me.CalendarControl0.DataProvider.ChangeEvent HitTest.ViewEvent.Event Else ' it was deleted and should be removed Me.CalendarControl0.DataProvider.DeleteEvent HitTest.ViewEvent.Event End If End If Me.CalendarControl0.Populate End Sub Hope this helps. |
|
JasonG
Groupie Joined: 07 July 2008 Status: Offline Points: 76 |
Post Options
Thanks(0)
|
Would this work using the builtin dialogs?
dlgCalendar.ParentHWND = hwnd dlgCalendar.Calendar = Calendar1 dlgCalendar.ShowNewEvent ......... 'How do I retrieve the event object from this, 'so I can add it to the database AddToDatabase(Event) |
|
Product: Xtreme SuitePro (ActiveX) 12.0.1
Platform: Windows Vista/XP Language: Visual Basic 6.0 SP6 |
|
StephenMurphy
Newbie Joined: 13 July 2008 Location: Canada Status: Offline Points: 8 |
Post Options
Thanks(0)
|
It should work fine with the built in dialogs. The only thing you need to do is add a new record to your db so you can get back your desired ID (or at least find out what the new ID will be, in case the user backs out in adding it to the calendar) before you create the new Event in the calendar. Something like this should work:
Private Sub CalendarControl0_DblClick() Dim dp As CalendarDataProvider Dim dlg As CalendarDialogs Dim HitTest As CalendarHitTestInfo Dim oEvent As CalendarEvent Dim bRet As Boolean Dim lID As Long Set dp = CalendarControl0.DataProvider Set HitTest = Me.CalendarControl0.ActiveView.HitTest Set dlg = New CalendarDialogs dlg.ParentHWND = Me.hWnd dlg.Calendar = CalendarControl0 If HitTest.ViewEvent Is Nothing Then ' clicked on day rather than event lID = FindNextID() ' Get your desired ID from your db by adding a new record or determining what the id will be... If lID <> 0 Then Set oEvent = dp.CreateEventEx(lID) ' Create a new event with your id oEvent.StartTime = HitTest.HitDateTime oEvent.EndTime = DateAdd("h", 1, HitTest.HitDateTime) bRet = dlg.ShowNewEvent2(oEvent) If bRet = True Then MsgBox "Item added" ' update your db using oEvent values or add it if you didn't before Else ' user backed out, kill event in db End If End If Else ' user clicked on existing event bRet = dlg.ShowEditEvent(HitTest.ViewEvent.Event) If bRet = True Then MsgBox "Item Edited" ' update your db with new info from HitTest.ViewEvent.Event End If End If End Sub |
|
JasonG
Groupie Joined: 07 July 2008 Status: Offline Points: 76 |
Post Options
Thanks(0)
|
I had to alter this pretty heavily to make it work, but I got it. Essentially, I am adding a BLANK event to the DB to establish the ID, then when the event is updated, I call my Update Function on that event. Works great!
Thanks alot! |
|
Product: Xtreme SuitePro (ActiveX) 12.0.1
Platform: Windows Vista/XP Language: Visual Basic 6.0 SP6 |
|
StephenMurphy
Newbie Joined: 13 July 2008 Location: Canada Status: Offline Points: 8 |
Post Options
Thanks(0)
|
Sounds good! Don't forget to delete the blank event in the DB if dlg.ShowNewEvent2(oEvent) returns False, ie the user hit the cancel button.
All the best. |
|
JasonG
Groupie Joined: 07 July 2008 Status: Offline Points: 76 |
Post Options
Thanks(0)
|
Yes. I already made that mistake (oops) :) Thanks again!
|
|
Product: Xtreme SuitePro (ActiveX) 12.0.1
Platform: Windows Vista/XP Language: Visual Basic 6.0 SP6 |
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |