PDA

View Full Version : checking all criteria for a contact from a user form before placing it in the to fiel



nocaffeine
09-11-2013, 10:16 PM
Hello! I've managed to solve what I was trying to figure out in my previous post and have made progress onto the main stuff. I've created a user form tailored to my contact form and I'm selecting different filters you could say to check if the contact meets the criteria, and if so, add it the the email. I've created a working algorithm for each section that works successfully on its own.

My current problem is this: When I click the 'submit' button, the form will figure out which sections are used, and if used, pull those emails. What I need to happen though is for all of the sections to be taken into account. So if the "member status" section is used and the "asset" section is used, pull contacts that have that selected member status with the matching asset range as well. This will work for at least 6 different sections to start with more to be added I'm sure. What's the best way to go about doing this? I don't want to make every possibility of a function, such as if boolMemberUsed = True And boolAsset = False And boolStateUsed = True Then... and so on. There must be a more straightforward, streamlined way to do this. I just can't think of it quite yet!

It needs to be something like...

With newEmail
For Each contact in myFolder.items
1) if memberUsed is true, check to see if contact matches selected member status
2) if there are other sections used, move to next section and check current contact against it
3) repeat until all sections are either gone through or skipped because it wasn't used

I think typing that semi-psuedo code might have helped me out, but any help is appreciated. Thank you.



'function to add emails what user has statuses selected and boolAsset is FALSE
If boolMembersUsed = True Then
With newEmail
For Each myContact In myFolder.Items
For count = 1 To arrayCt
If myContact.ItemProperties("memberStatus") = strMemberStatus(count) Then
strBCC = myContact.Email1Address & "; " & strBCC
End If
Next count
.BCC = strBCC
Next myContact
End With
End If

'function to add emails that are within asset range and nothing else
If boolAsset = True Then
With newEmail
For Each myContact In myFolder.Items
boolAssetRange = checkAssetRange(myContact.ItemProperties("assetAmt"))
If boolAssetRange = True Then
strBCC = myContact.Email1Address & "; " & strBCC
End If
.BCC = strBCC
Next myContact
End With
End If

'function to add emails that only have the state abbreviation in the field
If boolStateUsed = True Then
With newEmail
For Each myContact In myFolder.Items
If myContact.ItemProperties("sState") = cuState.Value Then
strBCC = myContact.Email1Address & "; " & strBCC
End If
.BCC = strBCC
Next myContact
End With
End If

SamT
09-12-2013, 12:45 PM
Are you wanting to add to BCC if any criteria are met?

i = 1
With newEmail
For Each myContact In myFolder.Items
If myContact.ItemProperties("memberStatus") = strMemberStatus(i) Then
strBCC = myContact.Email1Address & "; " & strBCC
ElseIf boolAssetRange = checkAssetRange(myContact.ItemProperties("assetAmt")) Then
strBCC = myContact.Email1Address & "; " & strBCC
ElseIf myContact.ItemProperties("sState") = cuState.Value Then
strBCC = myContact.Email1Address & "; " & strBCC
End If
i = i + 1
Next myContact
.BCC = strBCC
End With


'Alternate:
Flag As Boolean
i = 1
With newEmail
For Each myContact In myFolder.Items
Flag = Flag Or myContact.ItemProperties("memberStatus") = strMemberStatus(i)
Flag = Flag Or checkAssetRange(myContact.ItemProperties("assetAmt"))
Flag = Flag Or myContact.ItemProperties("sState") = cuState.Value
If Flag Then strBCC = myContact.Email1Address & "; " & strBCC
i = i + 1
Next myContact
.BCC = strBCC
End With