R
Rick Newton
I've been working for a while now on the addition of vbscript code to
the Open method for a new Appointment Form (based on using the basic
Appointment form).
The code seems straight-forward... I thought. It adds inforamtion to
the .Body of the item; specifically the current date, the user name of
the individual adding the appointment and requests a telephhone number
of the "contact" making the appointment [required info.].
Lastly the .Start and .End times are set using a formula to have the
start time to the nearest quarter-hour to the current time (but after
the current time) and sets the end time to 1 hour later.
The form has been saved/published to my Calendar area (I want to
eventually add the working form to a general area so that all staff
have access to the form from their Action menu -- but that's another
question... when the form works...)
The problem is this:
- When run through the "design" access (Run this Form) everything
works as expected and can be sent.
- When using the Published form (Actions menu , New <form_name>) the
..Body items appear as entered, but the date/time remain set to those
values that were on the form when published and after completing the
form (entering the recipient; in this case as a resource for booking
the location of the appointment) and selecting Send the following
message appears:
"The operation failed. An object could not be found. Unable to
directly book a resource for this meeting."
I've seen other messages in this group that have reported similar
errors, and as such tried Sue Mosher's suggestion regarding the
"repair" process for Office 2003/Outlook 2003 (we only have the
Outlook component as part of our licensing for Windows Server 2003
SBS). Unhfortunately, I've not been successful with these suggested
resolutions and am turning to those in this group with more experience
(this is my first Outlook form...) for any assistance you may be able
to provide.
Here is the vbscript code used (sorry about the length...) in the form
(note that there are calls to a library DLL named VBSINPUT.DLL which I
obtained from winntmag.com and is used to enhance the InputBox
vbsctipt call):
Function Item_Open()
'**************************************************************************************
'* Author: Rick Newton
'* Created: September 2, 2004.
'* Last Modified: September 8, 2004.
'*
'* This function executes when the form opens and asks for the
'* following information:
'* - Client's phone number
'* - Additional comments/information
'* The function automatically retrieves the username and the
'* current date and adds
'* this information to the body of the appointment.
'*
'* Note: Schedules new appointment for nearest quarter-hour to the
'* ==== current time by taking current time (in integer)
'* multiplying by 96 (the number of quarter-hours in a
'* day), adding 1 (quarter-hour) then dividing this new
'* value by 96 (again, the number of quarter-hours in a
'* day). Additionally, the duration of the appointment
'* is set to 1 hour (60 minutes)
'**************************************************************************************
Dim WshShell, strUserName, strPhoneNumber, strComments
Dim objCommentsDlg, NewTime, bValid
Dim vbResult, objPhoneNumberDlg, CurrentDayTime, CurrentDay
Dim CurrentTime, strPhoneMask, bCancel
' New Item default creation time
If Item.CreationTime = #1/1/4501# Then
'
' Create shell object
'
Set WshShell = CreateObject("Wscript.Shell")
'
' Determine the closet quarter-hour from the current time and
' use that as the 'default' start time for the appointment.
' The date 'default' will be the current day (Code snippet
' from MS KB article #201049: OL2000 - Incorrect
' Start Time for Appointments Using Custom Form)
'
CurrentDayTime = Now()
CurrentDay = Int(CurrentDayTime)
CurrentTime = CurrentDayTime - CurrentDay
NewTime = (Int(CurrentTime * 96) + 1)/96
'
' Define default values for variables used
' - string variables for the phone number, additional comments,
' and for storing the name of the user creating the
' appointment item
'
bValid = TRUE
bCancel = vbNo
strPhoneNumber = Empty
strComments = Empty
strPhoneMask = "###-###-####"
strUserName = _
UCase(Application.GetNameSpace("MAPI").CurrentUser)
'
' Request, using the special vbscript library VBSInput.DLL,
' the client's phone number
' Note: Validation of phone number is done; format is
' ###-###-####
'
Set objPhoneNumberDlg = CreateObject("VbsInput.InputBox")
objPhoneNumberDlg.Title = "Client's Phone Number - REQUIRED"
objPhoneNumberDlg.Label = "Enter Phone Number (including" &_
" area code) in the form " & strPhoneMask
objPhoneNumberDlg.Icon = "shell32.dll,54"
Do While (Len(strPhoneNumber) = 0) Or Not(bValid)
strPhoneNumber = Empty
strPhoneNumber = objPhoneNumberDlg.Show()
If Len(strPhoneNumber) = 0 Then
bCancel = WshShell.Popup("Cancel Adding Appointment?", , _
"Cancel?", vbYesNo)
If bCancel = vbYes Then 'Cancel addition
Item_Open = FALSE
Exit Function
End If
End If
If Len(strPhoneNumber) <> Len(strPhoneMask) Then
WshShell.Popup "Enter a valid phone number in the " &_
"format: " & strPhoneMask, , _
"Invalid Entry!", vbOKOnly+vbExclamation
bValid = FALSE
Else
If Right(Left(strPhoneNumber, 4), 1) <> "-" Then
WshShell.Popup "Enter a valid phone number in " &_
"the format: " & strPhoneMask, , _
"Invalid Entry!", vbOKOnly+vbExclamation
bValid = FALSE
Else
If Right(Left(strPhoneNumber, 8), 1) <> "-" Then
WshShell.Popup "Enter a valid phone number in " &_
"the format: " & strPhoneMask, , _
"Invalid Entry!", _
vbOKOnly+vbExclamation
bValid = FALSE
Else
If Not IsNumeric(Left(strPhoneNumber, 3)) Then
WshShell.Popup "Enter a valid phone number " &_
"in the format: " & strPhoneMask, , _
"Invalid Entry!", _
vbOKOnly+vbExclamation
bValid = FALSE
Else
If Not IsNumeric(Mid(strPhoneNumber, 5, 3)) Then
WshShell.Popup "Enter a valid phone " &_
"number in the format: " &_
strPhoneMask, , _
"Invalid Entry!", _
vbOKOnly+vbExclamation
bValid = FALSE
Else
If Not IsNumeric(Mid(strPhoneNumber, 9, 4)) _
Then
WshShell.Popup "Enter a valid phone " &_
"number in the format: " &_
strPhoneMask, , _
"Invalid Entry!", _
vbOKOnly+vbExclamation
bValid = FALSE
Else
bValid = TRUE
End If
End If
End If
End If
End If
End If
Loop
'
' Request, using the special vbscript library VBSInput.DLL,
' any additional comments to be added to the appointment's text
' body.
' Note: No validation of text entered is done!
'
Set objCommentsDlg = CreateObject("VbsInput.InputBox")
objCommentsDlg.Title = "Additional Information"
objCommentsDlg.Label = "Enter Your Comments (max. 250" &_
characters)"
objCommentsDlg.Icon = "shell32.dll,54"
objCommentsDlg.multiline = True
strComments = objCommentsDlg.Show()
'
' Set the appointment's start, end and reminder properties using
' previously calculated date/time information; the appointment
' end-time is 1 hour later than the calculated start-time; the
' appointment reminder is "off"
'
Item.Start = CurrentDay + NewTime
Item.End = DateAdd("H", 1, Item.Start)
Item.ReminderSet = FALSE
'
' Set the appointment's body text
'
Item.Body = "Client Ph. #: " & strPhoneNumber & vbCrLf &_
vbCrLf & "Date Booking Added: " &_
Date() & vbCrLf & "Booked By: " &_
strUserName & vbCrLf & vbCrLf & _
"Additional Comments: " & vbCrLf &_
vbCrLf & strComments
Item.Save
'
' Clear objects
'
Set objCommentDlg = Nothing
Set objPhoneNumberDlg = Nothing
Set WshShell = Nothing
End If
End Function
Thanks,
----
Rick Newton
IT Administration
Herpers Chagani Gowling, Inc.
300 - 4 Hughson Street South
Hamilton, ON L8N 3Z1
Canada
the Open method for a new Appointment Form (based on using the basic
Appointment form).
The code seems straight-forward... I thought. It adds inforamtion to
the .Body of the item; specifically the current date, the user name of
the individual adding the appointment and requests a telephhone number
of the "contact" making the appointment [required info.].
Lastly the .Start and .End times are set using a formula to have the
start time to the nearest quarter-hour to the current time (but after
the current time) and sets the end time to 1 hour later.
The form has been saved/published to my Calendar area (I want to
eventually add the working form to a general area so that all staff
have access to the form from their Action menu -- but that's another
question... when the form works...)
The problem is this:
- When run through the "design" access (Run this Form) everything
works as expected and can be sent.
- When using the Published form (Actions menu , New <form_name>) the
..Body items appear as entered, but the date/time remain set to those
values that were on the form when published and after completing the
form (entering the recipient; in this case as a resource for booking
the location of the appointment) and selecting Send the following
message appears:
"The operation failed. An object could not be found. Unable to
directly book a resource for this meeting."
I've seen other messages in this group that have reported similar
errors, and as such tried Sue Mosher's suggestion regarding the
"repair" process for Office 2003/Outlook 2003 (we only have the
Outlook component as part of our licensing for Windows Server 2003
SBS). Unhfortunately, I've not been successful with these suggested
resolutions and am turning to those in this group with more experience
(this is my first Outlook form...) for any assistance you may be able
to provide.
Here is the vbscript code used (sorry about the length...) in the form
(note that there are calls to a library DLL named VBSINPUT.DLL which I
obtained from winntmag.com and is used to enhance the InputBox
vbsctipt call):
Function Item_Open()
'**************************************************************************************
'* Author: Rick Newton
'* Created: September 2, 2004.
'* Last Modified: September 8, 2004.
'*
'* This function executes when the form opens and asks for the
'* following information:
'* - Client's phone number
'* - Additional comments/information
'* The function automatically retrieves the username and the
'* current date and adds
'* this information to the body of the appointment.
'*
'* Note: Schedules new appointment for nearest quarter-hour to the
'* ==== current time by taking current time (in integer)
'* multiplying by 96 (the number of quarter-hours in a
'* day), adding 1 (quarter-hour) then dividing this new
'* value by 96 (again, the number of quarter-hours in a
'* day). Additionally, the duration of the appointment
'* is set to 1 hour (60 minutes)
'**************************************************************************************
Dim WshShell, strUserName, strPhoneNumber, strComments
Dim objCommentsDlg, NewTime, bValid
Dim vbResult, objPhoneNumberDlg, CurrentDayTime, CurrentDay
Dim CurrentTime, strPhoneMask, bCancel
' New Item default creation time
If Item.CreationTime = #1/1/4501# Then
'
' Create shell object
'
Set WshShell = CreateObject("Wscript.Shell")
'
' Determine the closet quarter-hour from the current time and
' use that as the 'default' start time for the appointment.
' The date 'default' will be the current day (Code snippet
' from MS KB article #201049: OL2000 - Incorrect
' Start Time for Appointments Using Custom Form)
'
CurrentDayTime = Now()
CurrentDay = Int(CurrentDayTime)
CurrentTime = CurrentDayTime - CurrentDay
NewTime = (Int(CurrentTime * 96) + 1)/96
'
' Define default values for variables used
' - string variables for the phone number, additional comments,
' and for storing the name of the user creating the
' appointment item
'
bValid = TRUE
bCancel = vbNo
strPhoneNumber = Empty
strComments = Empty
strPhoneMask = "###-###-####"
strUserName = _
UCase(Application.GetNameSpace("MAPI").CurrentUser)
'
' Request, using the special vbscript library VBSInput.DLL,
' the client's phone number
' Note: Validation of phone number is done; format is
' ###-###-####
'
Set objPhoneNumberDlg = CreateObject("VbsInput.InputBox")
objPhoneNumberDlg.Title = "Client's Phone Number - REQUIRED"
objPhoneNumberDlg.Label = "Enter Phone Number (including" &_
" area code) in the form " & strPhoneMask
objPhoneNumberDlg.Icon = "shell32.dll,54"
Do While (Len(strPhoneNumber) = 0) Or Not(bValid)
strPhoneNumber = Empty
strPhoneNumber = objPhoneNumberDlg.Show()
If Len(strPhoneNumber) = 0 Then
bCancel = WshShell.Popup("Cancel Adding Appointment?", , _
"Cancel?", vbYesNo)
If bCancel = vbYes Then 'Cancel addition
Item_Open = FALSE
Exit Function
End If
End If
If Len(strPhoneNumber) <> Len(strPhoneMask) Then
WshShell.Popup "Enter a valid phone number in the " &_
"format: " & strPhoneMask, , _
"Invalid Entry!", vbOKOnly+vbExclamation
bValid = FALSE
Else
If Right(Left(strPhoneNumber, 4), 1) <> "-" Then
WshShell.Popup "Enter a valid phone number in " &_
"the format: " & strPhoneMask, , _
"Invalid Entry!", vbOKOnly+vbExclamation
bValid = FALSE
Else
If Right(Left(strPhoneNumber, 8), 1) <> "-" Then
WshShell.Popup "Enter a valid phone number in " &_
"the format: " & strPhoneMask, , _
"Invalid Entry!", _
vbOKOnly+vbExclamation
bValid = FALSE
Else
If Not IsNumeric(Left(strPhoneNumber, 3)) Then
WshShell.Popup "Enter a valid phone number " &_
"in the format: " & strPhoneMask, , _
"Invalid Entry!", _
vbOKOnly+vbExclamation
bValid = FALSE
Else
If Not IsNumeric(Mid(strPhoneNumber, 5, 3)) Then
WshShell.Popup "Enter a valid phone " &_
"number in the format: " &_
strPhoneMask, , _
"Invalid Entry!", _
vbOKOnly+vbExclamation
bValid = FALSE
Else
If Not IsNumeric(Mid(strPhoneNumber, 9, 4)) _
Then
WshShell.Popup "Enter a valid phone " &_
"number in the format: " &_
strPhoneMask, , _
"Invalid Entry!", _
vbOKOnly+vbExclamation
bValid = FALSE
Else
bValid = TRUE
End If
End If
End If
End If
End If
End If
Loop
'
' Request, using the special vbscript library VBSInput.DLL,
' any additional comments to be added to the appointment's text
' body.
' Note: No validation of text entered is done!
'
Set objCommentsDlg = CreateObject("VbsInput.InputBox")
objCommentsDlg.Title = "Additional Information"
objCommentsDlg.Label = "Enter Your Comments (max. 250" &_
characters)"
objCommentsDlg.Icon = "shell32.dll,54"
objCommentsDlg.multiline = True
strComments = objCommentsDlg.Show()
'
' Set the appointment's start, end and reminder properties using
' previously calculated date/time information; the appointment
' end-time is 1 hour later than the calculated start-time; the
' appointment reminder is "off"
'
Item.Start = CurrentDay + NewTime
Item.End = DateAdd("H", 1, Item.Start)
Item.ReminderSet = FALSE
'
' Set the appointment's body text
'
Item.Body = "Client Ph. #: " & strPhoneNumber & vbCrLf &_
vbCrLf & "Date Booking Added: " &_
Date() & vbCrLf & "Booked By: " &_
strUserName & vbCrLf & vbCrLf & _
"Additional Comments: " & vbCrLf &_
vbCrLf & strComments
Item.Save
'
' Clear objects
'
Set objCommentDlg = Nothing
Set objPhoneNumberDlg = Nothing
Set WshShell = Nothing
End If
End Function
Thanks,
----
Rick Newton
IT Administration
Herpers Chagani Gowling, Inc.
300 - 4 Hughson Street South
Hamilton, ON L8N 3Z1
Canada