none
CustomForm to display available meeting room RRS feed

  • Question

  • Hi,

    I want to be able to show for selection, only the available meeting room when I set a new appointment.

    I found code on the internet to do it. But I'm having hard time to implement...

    To keep it simple, I will not show the whole thing but just explain the initial challenge; I found 2 ways to implement it. 

    First one through VBA Project and second one through Outlook CustomForm using VBScript.

    It seems more "bestpractice" to use the CustomForm but I am screwed with VBScript. I can't find how to access the current Outlook session object model through VBScript.

    In VBA:

    Set myAddressList =

    Application.Session.AddressLists("Montreal, 2045 Stanley")

    Because of the code I already have built, it would be easier to work in VBA. But I do not have a clue how to implement this.  Hopefully someone knows on one or the other way :-)


    Yann.

    Monday, March 18, 2013 5:06 PM

Answers

  • I found the problem. Thanks. I had tried all differents ways to call it except the right one. So in French, it is "p. 2"  With a space between...


    Yann.

    Wednesday, March 20, 2013 1:44 PM

All replies

  • There's no difference.  The Application object is "intrinsic" and accessible as is in VBScript just like in VBA, without requiring you to declare another variable (although you certainly still can).

    Eric Legault MVP (Outlook)
    About me...
    Outlook Appins: Store Social Media fields in your Outlook Contacts!

    Monday, March 18, 2013 5:31 PM
    Moderator
  • Salut Eric,

    Thank for your help.

    Well it does not seems to work as this code results in error:

     

    Set myAddressList =

    Application.Session.AddressLists("Montreal, 2045 Stanley")

    Is there a way to call my VBA Form from the Customform and have the VBA Form to work on the same appointment object?


    Yann.

    Monday, March 18, 2013 5:38 PM
  • What error do you get?  Do you have an address list named "Montreal, 2045 Stanley"?  Have you tried iterating through the AddressLists collection to verify what lists you have?

    Yes, you can call a macro from your custom form but it's not officially supported:

    OL2000: Calling a VBA Procedure from VBScript
    http://support.microsoft.com/?kbid=221827


    Eric Legault MVP (Outlook)
    About me...
    Outlook Appins: Store Social Media fields in your Outlook Contacts!

    Monday, March 18, 2013 6:12 PM
    Moderator
  • I get "exception inconnue" (Unkown exception).

    I tried at an upper level so:

    Set myAddressList = Application.Session.AddressLists("All Rooms")

    Still getting the same error. I can't loop in the collection since I can't set the collection. That is why I wasen't sure if I could directly call the Application.Session.


    Yann.

    Monday, March 18, 2013 6:25 PM
  • Try this code:

    On Error Resume Next

    Dim objNS
    Dim objALs
    Dim objAL
    Dim intX

    Set objNS = Application.GetNamespace("MAPI")

    If objNS Is Nothing Then
         MsgBox("Something is really wrong")
         Exit Sub
    End If

    Set objALs = objNS.AddressLists

    If objALs Is Nothing Then
         MsgBox("Something is wrong")
         Exit Sub
    End If

    Set objAL = objALs.Item("Global Address List")

    If objAL Is Nothing Then
         MsgBox("Something is wrong")
         Exit Sub
    End If

    intX = objALs.Count

    For intX = 1 To objALs.Count
         Set objAL = objALs.Item(intX)
         MsgBox("Address List name: " & objAL.Name)
    Next


    Eric Legault MVP (Outlook)
    About me...
    Outlook Appins: Store Social Media fields in your Outlook Contacts!

    Monday, March 18, 2013 6:49 PM
    Moderator
  • It exits right at the beggining  "Something is really wrong".This is really weird. 


    Yann.

    Monday, March 18, 2013 7:46 PM
  • Paste the below into a your custom form and see what happens:

    Function Item_Open()
    On Error Resume Next
    
    Dim objNS
    Dim objALs
    Dim objAL
    Dim intX
    
    Set objNS = Application.GetNamespace("MAPI")
    
    If objNS Is Nothing Then
         MsgBox("Something is really wrong")
         Exit Function
    Else
    	MsgBox("So far so good")
    End If
    
    Set objALs = objNS.AddressLists
    
    If objALs Is Nothing Then
         MsgBox("Something is wrong")
         Exit Function
    End If
    
    Set objAL = objALs.Item("Global Address List")
    
    If objAL Is Nothing Then
         MsgBox("Something is wrong")
         Exit Function
    End If
    
    intX = objALs.Count
    
    For intX = 1 To objALs.Count
         Set objAL = objALs.Item(intX)
         MsgBox("Address List name: " & objAL.Name)
    Next
    
    End Function
        


    Eric Legault MVP (Outlook)
    About me...
    Outlook Appins: Store Social Media fields in your Outlook Contacts!

    Monday, March 18, 2013 8:38 PM
    Moderator
  • Salut Eric,

    Using your code to test, I was able to tests back and forth and get things to work!  So in the code window, you can see how I was able to implement it with minor modifications.

    I haven't really check for now if the Rooms thata re returned are really the ones availalble. I'll test later. For now, I am blocked at the moment I need to add the Rooms to the Listbox.  The method using Private Sub lbxRooms_DblClick(ByVal Cancel) is not working. 

    I tried another methoed from a MS code exemple.  It starts at the line " Set FormPage = Item.GetInspector.ModifiedFormPages("p.2")"

    I do not receive any error, but the Listbox is not populating. If I use the Msgbox to display the Rooms Name, It works. The Msgbox shows 21 times.  That seems to be again related to how it is implemented with outlook.  D'you have an idea on this one?

    Option Explicit Dim strCity 'city code used in address name Dim strRooms 'address entries Dim Meeting 'current meeting Dim myRecipient 'the room I finally pick Dim UseThisRoom 'the room I finally pick Dim myAddressList 'address list Dim AddressEntry 'addressentry Dim myRooms Dim objNamespace Dim objSession Function Item_Open() myRooms = "Montreal, 2045 Stanley" 'use the global address book, incase another is default Set objNamespace = Application.GetNamespace("MAPI") Set objSession = Application.Session Set myAddressList = objSession.AddressLists(myRooms) ' go through address book and get each meeting room For Each AddressEntry In myAddressList.AddressEntries strRooms = AddressEntry.Name 'Msgbox(strRooms) 'look for the available rooms Call GetFreeBusyInfo Next End Function Sub GetFreeBusyInfo() Dim myFBInfo 'getfreebusy information for the meeting date Dim MyStart 'meeting start tiem and date Dim MyDur 'number of minutes in length the meeting is Dim MyStartTime 'number of minutes after midnight meeting starts 'use the active meeting as reference 'Set Meeting = Outlook.ActiveInspector.CurrentItem Set Meeting = Application.ActiveInspector.CurrentItem MyStart = Meeting.Start 'get the meeting start from active meeting MyDur = Meeting.Duration - 1 'get dureation from active meeting 'get number of minutes between midnight and MyStart 'MyStartTime = DateDiff("n", (Format(MyStart, "Short Date") & "12:00:00 AM"), MyStart) MyStartTime = DateDiff("n", (FormatDateTime(MyStart, vbShortDate) & " 12:00:00 AM"), MyStart) 'msgbox(MyStartTime) '(always 510 ?) On Error resume next 'ignore rooms that where freebusy is not available 'get the freebusy time for the meetign date myFBInfo = AddressEntry.GetFreeBusy(MyStart, 1) 'see if time is available (all minutes within meeting duration are 0) 'MsgBox(Mid(myFBInfo, MyStartTime, MyDur)) If Mid(myFBInfo, MyStartTime, MyDur) = 0 Then 'if available add it to the listbox 'MsgBox ("I'm here") 'Msgbox(AddressEntry.Name) ' Sets the name of page on the form (p.2) Set FormPage = Item.GetInspector.ModifiedFormPages("p.2") ' Sets Control to a list box called ListBox1. Set Control = FormPage.Controls("LbxRooms") ' Assign values to the list box. Control.PossibleValues = "Blue;Green;Red;Yellow" Application.lbxRooms.AddItem AddressEntry.Name End If ErrorHandler: End Sub Private Sub lbxRooms_DblClick(ByVal Cancel) Msgbox("I Click") 'use the room that is double clicked on UseThisRoom = lbxRooms.Value 'add the selected room to current object as a resource Set Meeting = Outlook.ActiveInspector.CurrentItem Set myRecipient = Meeting.Recipients.Add(UseThisRoom) myRecipient.Type = olResource 'unload form after room is added, since only one room is ever needed 'Unload Me End Sub Private Sub cmdCancel_Click() 'cancel and close the form without adding a room Unload Me End Sub

     

    ....

    End Function...



    Yann.

    Tuesday, March 19, 2013 3:11 PM
  • The only event available to any control in VBScript is the Click event.  Just adapt to that instead of double click.

    Eric Legault MVP (Outlook)
    About me...
    Outlook Appins: Store Social Media fields in your Outlook Contacts!

    Tuesday, March 19, 2013 3:17 PM
    Moderator
  • I'll do so when the listbox is fixed.  For now, I can't populate the listbox.  So it seems seems like I cannot interact with the controls of my Custom Form.

    I found this code on MS:

    http://support.microsoft.com/?kbid=290819

    But I can't make it work. It does not created the object.

    I added a new ListBox and directly pasted the code. I get "Erreur d'exécution Microsoft VBScript: Objet requis: 'FormPage'". So the object is not created. Have a tip for me (again)?

    Function Item_Open()
    Dim FormPage
    Dim Control
    ' Sets the name of page on the form (P.2)
       Set FormPage = Item.GetInspector.ModifiedFormPages("P.2")
       ' Sets Control to a list box called ListBox1.
       Set Control = FormPage.Controls("ListBox1")
       ' Assign values to the list box.
       Control.PossibleValues = "Blue;Green;Red;Yellow"


    Yann.

    Tuesday, March 19, 2013 5:28 PM
  • Do you have a P.2 page with any controls on it? The page must be visible and have controls on it.  BTW, your comments in the code indicate that you are trying to change the name of the page, but you can't do that in code.

    This works fine for me with a Listbox added to P.2:

    Function Item_Open()
    
    	Dim FormPage
    	Dim Control
    	' Sets the name of page on the form (P.2)
    	Set FormPage = Item.GetInspector.ModifiedFormPages("P.2")
    	If FormPage Is Nothing Then
    		Msgbox("No FormPage")
    	Else
    		Msgbox("Success retrieving FormPage")
    	End If
    
    	' Sets Control to a list box called ListBox1.
    	Set Control = FormPage.Controls("ListBox1")
    
    	If Control Is Nothing Then
    		Msgbox("No Control")
    	Else
    		Msgbox("Success retrieving Control")
    	End If
    
    End Function
    


    Eric Legault MVP (Outlook)
    About me...
    Outlook Appins: Store Social Media fields in your Outlook Contacts!

    Tuesday, March 19, 2013 5:47 PM
    Moderator
  • Result is "No FormPage".  I think perhaps it's related to the name of the form?  I'm using Frech version.  The TAB seems to be "p. 2". But it does not wrok either.

    the "Propertie" button for the form is grayed. So I canT' do a Copy Paste of the form name in my code.:


    Yann.

    Tuesday, March 19, 2013 5:59 PM
  • Try again - it's definitely case specific. I changed my call to "p.2" and it failed, as my page is named "P.2".

    Eric Legault MVP (Outlook)
    About me...
    Outlook Appins: Store Social Media fields in your Outlook Contacts!

    Tuesday, March 19, 2013 7:02 PM
    Moderator
  • I found the problem. Thanks. I had tried all differents ways to call it except the right one. So in French, it is "p. 2"  With a space between...


    Yann.

    Wednesday, March 20, 2013 1:44 PM