Concatenating data from multiple checkboxes

melody.anne

Registered User.
Local time
Today, 05:56
Joined
Feb 27, 2015
Messages
43
I have 8 checkboxes. Each checkbox has several e-mail addresses as string. Therefore, each checkbox has a string variable declared. I was wondering what should I do when selecting multiple check boxes. This is my code:
Code:
If Me!chkAGDLLA = True Then
Forms!email.lstName = Null
Forms!email.chkComercial = False
Forms!email.chkOperacional = False
strAGDLLA = "email1, email2, email3, email4"
strMail = strAGDLLA & ", " & strISA & ", " & strMAYA & ", " & strSANGER & "," & strSANSE & ", " & strSede & ", " & strGC & ", " & strCSR
MsgBox strMail
End If

Problem is that if I only select chkAGDLLA, then strMail will be "email1, email2, email3, email4, , , , , , ,"

I do not want all those commas, but I have no idea how to make this work. I was thinking maybe a SELECT CASE so that strMail will accumulate data based on what's checked, but then there will be a problem of there being no comma between cases.
 
I don't understand this . . .
Each checkbox has several e-mail addresses as string. Therefore, each checkbox has a string variable declared.
A checkbox is a control that might have two values, true and false. True when checked, false when not checked. How can it "have" several email addresses?
 
I don't understand this . . .

A checkbox is a control that might have two values, true and false. True when checked, false when not checked. How can it "have" several email addresses?

When a checkbox is true I designated it to have a string in which I entered the emails manually. A check box is an office, and each office has several people, therefore when I check the checkbox for that office, it will send the email to everyone in that office.
 
. . . I designated it to have a string . . .
I still don't understand this. You designated a checkbox to have a string, ok, but how did you do that? Presumably you want to access that string when the checkbox is checked, but in order for us to advise you on that, you need to tell us how the string is linked or connected. So if I click checkbox1, where are the email addresses that this checkbox "has?"
 
I still don't understand this. You designated a checkbox to have a string, ok, but how did you do that? Presumably you want to access that string when the checkbox is checked, but in order for us to advise you on that, you need to tell us how the string is linked or connected. So if I click checkbox1, where are the email addresses that this checkbox "has?"
It's right in the code I posted,

Code:
If Me!chkAGDLLA = True Then
Forms!email.lstName = Null
Forms!email.chkComercial = False
Forms!email.chkOperacional = False
[B][COLOR=red]strAGDLLA = "email1, email2, email3, email4[/COLOR][/B][COLOR=red]"[/COLOR]
strMail = strAGDLLA & ", " & strISA & ", " & strMAYA & ", " & strSANGER & "," & strSANSE & ", " & strSede & ", " & strGC & ", " & strCSR
MsgBox strMail
End If

But like I said, this does not work properly or at all. Because if I were to check the checkbox after this one and this one, it would output the exact same thing.

So instead I have this code:

Code:
If Me!chkGC = True Then
    Forms!email.lstName = Null
    Forms!email.chkComercial = False
    Forms!email.chkOperacional = False
    strMail = "[EMAIL="carmen@apr.com"]carmen@apr.com[/EMAIL], [EMAIL="roberto@apr.com"]roberto@apr.com[/EMAIL]"
    
    MsgBox strMail

    Forms!email.chkGC = False

End If

But there's no way of outputting the results of more than one checkbox at a time with this code.
 
It's right in the code I posted,

Code:
If Me!chkAGDLLA = True Then
Forms!email.lstName = Null
Forms!email.chkComercial = False
Forms!email.chkOperacional = False
[B][COLOR=red]strAGDLLA = "email1, email2, email3, email4[/COLOR][/B][COLOR=red]"[/COLOR]
strMail = strAGDLLA & ", " & strISA & ", " & strMAYA & ", " & strSANGER & "," & strSANSE & ", " & strSede & ", " & strGC & ", " & strCSR
MsgBox strMail
End If

But like I said, this does not work properly or at all. Because if I were to check the checkbox after this one and this one, it would output the exact same thing.

So instead I have this code:

Code:
If Me!chkGC = True Then
    Forms!email.lstName = Null
    Forms!email.chkComercial = False
    Forms!email.chkOperacional = False
    strMail = "[EMAIL="carmen@apr.com"]carmen@apr.com[/EMAIL], [EMAIL="roberto@apr.com"]roberto@apr.com[/EMAIL]"
 
    MsgBox strMail
 
    Forms!email.chkGC = False
 
End If

But there's no way of outputting the results of more than one checkbox at a time with this code.

m-a,
are you sure of this ? If you start with an empty strMail then you can run it through a series of filters based on the checkboxes each with
Code:
strMail=strMail & ", " & checkboxstring (substitute real name)

So you only collect the addresses in the offices of the checkboxes that have been checked.

In the end remove the leading leading comma. Is there anything I have missed here ?

Best,
Jiri
 
Well, I see it now that it's marked in red. Sheesh. :)
 

Users who are viewing this thread

Back
Top Bottom