Voting button

S

stanhope4

Hi,

I currently have two voting buttons setup 'approve' and 'deny', i am
trying to code (a bit of a novice) so that when i click the apprioriate
button it opens a new email containing relevent information from a
previous form.

below is the code:

select case Action.Name
case "Approval"
Set Newitem = Application.CreateItem(olMailItem)
item.userproperties.find("Approve") = true
Actions.Item("Approve").Enabled = False
Actions.Item("Deny").Enabled = False
NewItem.Body = "Your request from" &
(item.userproperties.find("txtHolStart")) &
" to " & (item.userproperties.find("txtHolEnd")) & "for
" & (item.userproperties.find("totaldays"))& " days leave has been
approved."
case "Deny"
item.userproperties.find("Denied") = true
Actions.Item("Approve").Enabled = False
Actions.Item("Deny").Enabled = False
NewItem.Body = "Your request from " &
(item.userproperties.find("txtHolStart")) &
" to " & (item.userproperties.find("txtHolEnd")) & "for
" & (item.userproperties.find("Totaldays"))& " days leave has been
denied."
end select

item.close(0)

Item_CustomAction = true

not sure what im doing wrong but i keep getting a 'syntax error' on the
line :
NewItem.Body = "Your request from" &
(item.userproperties.find("txtHolStart")) &

also i would like to add reciepients into this email so any help with
that would be much appricated!

Thanks in advance.
 
S

Sue Mosher [MVP-Outlook]

txtHolStart sounds like the name of a control, not a custom property. They use different syntaxes; see http://www.outlookcode.com/d/propsyntax.htm

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
S

stanhope4

i have changed the name of the control to reflect the names i have used
in the all fields tab and it still comes up with the same syntax
error!! as i said i'm a novice but looking around the net it appears
that i'm using the correct code?! any help would be appricated.
 
S

Sue Mosher [MVP-Outlook]

Show your new code please and indicate what statement(s) are raising errors.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
S

stanhope4

Function Item_CustomAction(ByVal Action, ByVal NewItem)

select case Action.Name
case "Approve"
Set Newitem = Application.CreateItem(olMailItem)
item.userproperties.find("Approve") = true
Actions.Item("Approve").Enabled = True
Actions.Item("Deny").Enabled = True
Newitem.subject = "Holiday Request Approved"
NewItem.Body = "Your request from"
&(item.userproperties.find("HolidayStart")) &
" to " & (item.userproperties.find("HolidayEnd")) & "for
" & (item.userproperties.find("totaldays"))& " days leave has been
approved."

case "Deny"
item.userproperties.find("Deny") = true
Actions.Item("Approve").Enabled = True
Actions.Item("Deny").Enabled = True
Newitem.subject "Holiday Request Denied"
NewItem.Body = "Your request from " &
(item.userproperties.find("HolidayStart")) &
" to " & (item.userproperties.find("HolidayEnd")) & "for
" & (item.userproperties.find("Totaldays"))& " days leave has been
denied."
end select

item.close(0)

Item_CustomAction = true

end function

line " NewItem.Body = "Your request from"
&(item.userproperties.find("HolidayStart")) &" is coming up with error
'syntax error' when i run the form.

have 2 buttons approve and deny and i want to create a new email when
relevent button is pressed to create a new email with the relevent data
in the email body.
 
S

stanhope4

i have managed to change the code slightly so that the syntax error
doesn't occur but when clicking the approve button it still doesn't
create an email as coded?! still stuck!
 
S

Sue Mosher [MVP-Outlook]

Comments inline

stanhope4 said:
Function Item_CustomAction(ByVal Action, ByVal NewItem)

select case Action.Name
case "Approve"
Set Newitem = Application.CreateItem(olMailItem)

Why are you creating a new message here? NewItem is already a response created by the custom action.
item.userproperties.find("Approve") = true
Actions.Item("Approve").Enabled = True
Actions.Item("Deny").Enabled = True

IIRC, the above two statements will one-off the current item so that it will never run code again. I'd recommend you remove them.
Newitem.subject = "Holiday Request Approved"
NewItem.Body = "Your request from"
&(item.userproperties.find("HolidayStart")) &
" to " & (item.userproperties.find("HolidayEnd")) & "for
" & (item.userproperties.find("totaldays"))& " days leave has been
approved."

case "Deny"
item.userproperties.find("Deny") = true
Actions.Item("Approve").Enabled = True
Actions.Item("Deny").Enabled = True

Ditto.
Newitem.subject "Holiday Request Denied"
NewItem.Body = "Your request from " &
(item.userproperties.find("HolidayStart")) &
" to " & (item.userproperties.find("HolidayEnd")) & "for
" & (item.userproperties.find("Totaldays"))& " days leave has been
denied."
end select

item.close(0)

Item_CustomAction = true

The above statement is unneccessary. If you wanted to suppress the NewItem created by the action, you'd set the return value to False.

If you want to show the message created by the action, you need to include a NewItem.Display statement.
end function

line " NewItem.Body = "Your request from"
&(item.userproperties.find("HolidayStart")) &" is coming up with error
'syntax error' when i run the form.

You need a space between the ampersand $ and the parenthesis.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top