Email different messages based on check boxes

F

Fred

Hi,
I have a parking database that I need to send emails out to people once
they have been assigned a parking spot. I have 3 different types of
parking (handicap, VIP and Regular).
The problem is I have 2 check boxes one for VIP and 1 for handicap and
I have written my code as follows:
'***creates an instance of Outlook
Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)
FollowHyperlink "mailto:" & Me.Email.Value

If Me!VIP = 0 Then
'***creates and sends email
With objEmail
.To = Email
.CC = "(e-mail address removed)"
.Subject = ref & "Suffolk Visitor Parking " & origin & " " &
destination
.Body = "Parking for " & Me.[First Name] & " " & Me.[Last Name] & "
is confirmed. Please park in spaces 663-672 If these parking spaces are
full find a open space to park Thank You"
.Send
End With
End If

If Me!VIP = -1 Then
'***creates and sends email
With objEmail
.To = Email
.CC = "(e-mail address removed)"
.Subject = ref & "Suffolk Visitor Parking " & origin & " " &
destination
.Body = "Parking for " & Me.[First Name] & " " & Me.[Last Name] & "
is confirmed. Please park in space 662 Thank You"
.Send
End With
End If

If Me!Handicap = -1 Then
'***creates and sends email
With objEmail
.To = Email
.CC = "(e-mail address removed)"
.Subject = ref & "Suffolk Visitor Parking " & origin & " " &
destination
.Body = "Parking for " & Me.[First Name] & " " & Me.[Last Name] & "
is confirmed. Please park in Handicap spaces 135 or 136 Thank You"
.Send
End With
End If

When I do this if I check handicap it does not recognize the check box
and go to the third email it treats it like a regular and throws an
error. Thanx for anyhelp you can provide
 
A

Al Campagna

Fred,
I don't see your REGULAR code anywhere...
But more importantly, your logic won't work... From the code you've indicated I would
expect that if HCP is True and VIP = False, your code will fire on the VIP = False code
AND also HCP = True code
If you say all choices now fall into the REGULAR code, then there's something missing
in your description of your fields or setup, because if what you wrote is true,
"something" would fire... even if it was the wrong category/s.

Let's try a different tack...
Consider using an OptionGroup (ex. optParkingCategory) with 1= VIP1 2= VIP2 3=HCP
4=REG
That forces only one parking category to be selected at any one time. Since you are
now only interrogating one field, you can use a Select Case statement.
Select Case optParkingCategory
Case 1
'VIP1 code
Case 2
'Vip2 Code
Case 3
'HCP Code
Case 4 '(or Case Else)
'Reg Code
End Select

Also, try a Refresh after you update the optParkingCategory.
--
hth
Al Campagna
Candia Computer Consulting - Candia NH
http://home.comcast.net/~cccsolutions

Fred said:
Hi,
I have a parking database that I need to send emails out to people once
they have been assigned a parking spot. I have 3 different types of
parking (handicap, VIP and Regular).
The problem is I have 2 check boxes one for VIP and 1 for handicap and
I have written my code as follows:
'***creates an instance of Outlook
Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)
FollowHyperlink "mailto:" & Me.Email.Value

If Me!VIP = 0 Then
'***creates and sends email
With objEmail
.To = Email
.CC = "(e-mail address removed)"
.Subject = ref & "Suffolk Visitor Parking " & origin & " " &
destination
.Body = "Parking for " & Me.[First Name] & " " & Me.[Last Name] & "
is confirmed. Please park in spaces 663-672 If these parking spaces are
full find a open space to park Thank You"
.Send
End With
End If

If Me!VIP = -1 Then
'***creates and sends email
With objEmail
.To = Email
.CC = "(e-mail address removed)"
.Subject = ref & "Suffolk Visitor Parking " & origin & " " &
destination
.Body = "Parking for " & Me.[First Name] & " " & Me.[Last Name] & "
is confirmed. Please park in space 662 Thank You"
.Send
End With
End If

If Me!Handicap = -1 Then
'***creates and sends email
With objEmail
.To = Email
.CC = "(e-mail address removed)"
.Subject = ref & "Suffolk Visitor Parking " & origin & " " &
destination
.Body = "Parking for " & Me.[First Name] & " " & Me.[Last Name] & "
is confirmed. Please park in Handicap spaces 135 or 136 Thank You"
.Send
End With
End If

When I do this if I check handicap it does not recognize the check box
and go to the third email it treats it like a regular and throws an
error. Thanx for anyhelp you can provide
 
B

Barry Gilbert

Is Handicap the name of your checkbox or a field in the underlying data?
Also, what is the error message?

You might try:
If Me.Handicap Then
....

Barry
 
J

Jeff L

It looks you just need one little change. Change your first IF
statement to

If Me!VIP = 0 And Me!Handicap = 0 Then

Hope that helps!
 
F

Fred

Thanx alot all that helped Jeff that was all I needed thanx I thought
it was something like that just couldnt figure it out. Fred
Jeff said:
It looks you just need one little change. Change your first IF
statement to

If Me!VIP = 0 And Me!Handicap = 0 Then

Hope that helps!

Hi,
I have a parking database that I need to send emails out to people once
they have been assigned a parking spot. I have 3 different types of
parking (handicap, VIP and Regular).
The problem is I have 2 check boxes one for VIP and 1 for handicap and
I have written my code as follows:
'***creates an instance of Outlook
Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)
FollowHyperlink "mailto:" & Me.Email.Value

If Me!VIP = 0 Then
'***creates and sends email
With objEmail
.To = Email
.CC = "(e-mail address removed)"
.Subject = ref & "Suffolk Visitor Parking " & origin & " " &
destination
.Body = "Parking for " & Me.[First Name] & " " & Me.[Last Name] & "
is confirmed. Please park in spaces 663-672 If these parking spaces are
full find a open space to park Thank You"
.Send
End With
End If

If Me!VIP = -1 Then
'***creates and sends email
With objEmail
.To = Email
.CC = "(e-mail address removed)"
.Subject = ref & "Suffolk Visitor Parking " & origin & " " &
destination
.Body = "Parking for " & Me.[First Name] & " " & Me.[Last Name] & "
is confirmed. Please park in space 662 Thank You"
.Send
End With
End If

If Me!Handicap = -1 Then
'***creates and sends email
With objEmail
.To = Email
.CC = "(e-mail address removed)"
.Subject = ref & "Suffolk Visitor Parking " & origin & " " &
destination
.Body = "Parking for " & Me.[First Name] & " " & Me.[Last Name] & "
is confirmed. Please park in Handicap spaces 135 or 136 Thank You"
.Send
End With
End If

When I do this if I check handicap it does not recognize the check box
and go to the third email it treats it like a regular and throws an
error. Thanx for anyhelp you can provide
 

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