Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBScript adding entry to outlook not working

Status
Not open for further replies.

MoleDirect

Technical User
Sep 4, 2007
45
US
Greetings... Im having trouble getting a vbscript to add a calendar item to outlook.. the variable "whenwhen" actually equals out to a date, but is made of other variables like the following:
Code:
whenwhen = ("#" & whenday & " " & whentime & "#")
when you look at the value, it comes out to this example:
#8/6/2009 11:05 PM#

here is the code that adds the item:
Code:
olEvent.Start = whenwhen
olEvent.Subject = subject
olEvent.ReminderSet = True
olEvent.ReminderMinutesBeforeStart = 1
olEvent.Attachments.Add "C:\remtemp\RemedyTicket " & iklogname & ".ARTask", _
olByValue, 1, "Test"
olEvent.Save

Now, if I just change the value:

olEvent.Start = whenwhen

to

olEvent.Start = #8/6/2009 11:05 PM#

it works fine, even though they are both the same thing.. I need it to work using the value "whenwhen"

The error i get is:
Code:
Type Mismatch: Cannot coerce parameter value. Outlook cannot translate your string.
Code: 80020005
Source: Microsoft Office Outlook

Any ideas?
 
I'd try this:
Code:
whenwhen = CDate(whenday & " " & whentime)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
It will fail if the user doesn't enter a time as you filling whentime with a full date and time (which when paired with whendate can't be converted to a date as it is invalid hence the error). Try:
Code:
whentime = DateAdd("h",+1,Time())
Also you have no validation (or error handling) on your code, so if the user enters something the script isn't expecting it will blow up. Maybe, rather than
Code:
If whenday = "" Then...
If whentime = "" Then...
You could try
Code:
If Not IsDate(whenday) Then...
If Not IsDate(whentime) Then...
Maybe even a combination of the two depending what you want to happen if the user enters an invalid time or date.

Hope this helps

HarleyQuinn
---------------------------------
Black coat, white shoes, black hat, cadillac. The boy's a timebomb!

You can hang outside in the sun all day tossing a ball around, or you can sit at your computer and do something that matters. - Eric Cartman

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before post
 
Actually, you can ignore the first point. What you could do is NOT add the #'s the whenwhen and do a CDate on that instead. The reason for this is that it's quite possible whenday and whentime will both have values which will break CDate(), whereas whenwhen will only have one value.

I'd still recommend the validation of the input though...

HarleyQuinn
---------------------------------
Black coat, white shoes, black hat, cadillac. The boy's a timebomb!

You can hang outside in the sun all day tossing a ball around, or you can sit at your computer and do something that matters. - Eric Cartman

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before post
 
Excellent call on the validation... However, I am getting an error with the cDate:

Type mismatch: 'CDate'
Code: 800A000D
VB Runtime error

Here is the new code, I also added functions out thew wazoo to control moving around in the script. Im a noob :]

[script]
' developed by Mike KOvacic
' Remedy Reminder script
' Soursecode is copyright Mike Kovacic and IKON
' Instructions for use:
'
' ¤ Doubleclick on the script
' ¤ Insert Ticket number not including zeros || Hit OK
' ¤ Insert short description, this is what will show up in outlook as the item || Hit OK
' ¤ Insert the time in minutes that outlook should remind you. By default, the reminder will notify you 1 minute before you set the time
' ¤ Keep in mind that there are 60 minutes in an hour and 1440 minutes in a day. || Hit OK
' ¤ Afer a short pause, the reminder will be created. It can be edited or removed by going into your outlook calendar and opening the item.
'
' That all there is to it. One thing to keep in mind,this scrip[t will create a folder located at C:\remtemp
' You may wish to clean this folder, but any future remedy reminders createdby this program you have set may not work.
' You can also use this folder to see what tickets you have set in the past.
'
'
' Have Fun, source code is shown below, don't change it unless you know what you are doing, and do not remove this notice. :)

Call Main

function main
Dim objFSO, objFolder, objShell, strDirectory,WshShell,iklogname,subject,whenday,whentime,whenwhen,remedyticket,OlApp,nsNameSpace,olFolderCalendar,olEvent,olByValue,a,b
a = a
strDirectory = "c:\remtemp"
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(strDirectory) Then
Set objFolder = objFSO.GetFolder(strDirectory)
else
Set objFolder = objFSO.CreateFolder(strDirectory)
end if
Set WshShell = WScript.CreateObject("WScript.Shell")
call askremedy
end function

function askremedy
iklogname = InputBox("Input your Remedy Ticket number." & vbCrLf &"[not including the zeros.]", "Remedy Ticket Number v. 1.3")
If iklogname = "" Then
call badremnumber
Else
subject = InputBox("Give a quick description of ticket."& vbCrLf &" [example: user is back from vacation, reinstall vpn]", "Quick description")
END IF
call askday
end function

function askday
whenday = Inputbox("What DAY would you like to set this reminder for? "& vbCrLf &"[Leave field blank for today]" & vbCrLf & vbCrLf & "(Format: "& date() & ")" , "Remind me in...")
If whenday = "" Then
whenday = Date()
end if
If Not IsDate(whenday) Then
call baddate
end if
call asktime
end function

function asktime
whentime = Inputbox("What TIME would you like to set this reminder for? "& vbCrLf &"[Leave field blank for one hour]" & vbCrLf & vbCrLf & "(Format: "& time() & ")" , "Remind me in...")
whenwhen = (whenday & " " & whentime)
'whenwhen = ("#" & whenday & " " & whentime & "#")
If whentime = "" Then
a = b
whentime = DateAdd("h",+1,Time())
whenwhen = (whentime)
'whenwhen = ("#"& whentime & "#")
end if
If Not IsDate(whentime) Then
call badtime
end if
call makefile
end function


function makefile
DIM fso, GuyFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set remedyticket = fso.CreateTextFile( "C:\remtemp\RemedyTicket " & iklogname & ".ARTask", True)
remedyticket.WriteLine("[Shortcut]")
remedyticket.WriteLine ("Name = HPD:HelpDesk")
remedyticket.WriteLine ("Type = 0")
remedyticket.WriteLine ("Server = MyRemedyServer")
remedyticket.WriteLine ("Join = 0")
remedyticket.WriteLine ("Ticket = 00000000" & iklogname)
remedyticket.Close
call addreminder
end function

function addreminder
Set OlApp = CreateObject("Outlook.Application")
Set nsNameSpace = OlApp.GetNamespace("MAPI")
Set olFolderCalendar = nsNameSpace.GetDefaultFolder(9) 'olFolderCalendar
Set olEvent = OlApp.CreateItem(1)
'olAppointmentItem
'olEvent.Start = DateAdd("n", when, Now())


whenwhen = CDate(whenday & " " & whentime)
msgbox ("CDate = " & whenwhen)

'whenwhen = (#8/6/2009 11:05 PM#)
msgbox whenwhen
olEvent.Start = whenwhen
olEvent.Subject = subject
olEvent.ReminderSet = True
olEvent.ReminderMinutesBeforeStart = 5
olEvent.Attachments.Add "C:\remtemp\RemedyTicket " & iklogname & ".ARTask", _
olByValue, 1, "Test"
olEvent.Save
call finalword
end function

function finalword
MsgBox ("Ticket: " & iklogname & vbCrLf & "Subject: " & subject & vbCrLf & "Date: " & whenday & vbCrLf & "Time : " & whentime & vbCrLf & vbCrLf & "The event has been created in your Outlook calendar. Should you need to cancel or change your reminder, it must be done through outlook.")
end function

function baddate
MsgBox ("Please try again, use the following format: m/dd/yy")
Call askday
end function

function badtime
MsgBox ("Please try again, use the following format: h:mm (AM/PM)")
Call asktime
end function

function badremnumber
MsgBox ("I can not create a reminder if you don't give me a ticket number.")
call askremedy
end function
[/script]




















 
Instead of using it on whenday & " " & whentime try using CDate on whenwhen e.g.
Code:
dtMyFinalDate = CDate(whenwhen)
Hope this helps

HarleyQuinn
---------------------------------
Black coat, white shoes, black hat, cadillac. The boy's a timebomb!

You can hang outside in the sun all day tossing a ball around, or you can sit at your computer and do something that matters. - Eric Cartman

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before post
 
I tried it, but it still does not appear to be working... I am, however, setting whenwhen to equal the date and time variables like so:

Code:
whenwhen = ("" & whenday & " " & whentime & "")
dtMyFinalDate = CDate (whenwhen)

I just need to get the whentime and whenday together somehow.
 
think i found my problem... somewhere in the script, the values are getting lost...

I will let you know what i find out...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top