Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ms access 如果选中复选框,则尝试向其他人发送电子邮件_Ms Access_Vba - Fatal编程技术网

Ms access 如果选中复选框,则尝试向其他人发送电子邮件

Ms access 如果选中复选框,则尝试向其他人发送电子邮件,ms-access,vba,Ms Access,Vba,我正在使用Access、表单和子表单,并尝试循环检查复选框,如果选中了复选框,则向被选中的人发送电子邮件 问题是找不到方法或数据成员。 这一行抛出一个错误。 Me.qry\u Ryan\u电子邮件。Work\u电子邮件 Option Compare Database Private Sub Command1_Click() For Each ctrl In Me.qry_Ryan_Emails.Controls If TypeName(ctrl) = "CheckBox" Then

我正在使用Access、表单和子表单,并尝试循环检查复选框,如果选中了复选框,则向被选中的人发送电子邮件

问题是找不到方法或数据成员。 这一行抛出一个错误。 Me.qry\u Ryan\u电子邮件。Work\u电子邮件

Option Compare Database

Private Sub Command1_Click()

For Each ctrl In Me.qry_Ryan_Emails.Controls

    If TypeName(ctrl) = "CheckBox" Then
        If ctrl.Enabled = True Then
            'Debug.Print TypeName(ctrl)

            Set OutApp = CreateObject("Outlook.Application")
                Set OutMail = OutApp.CreateItem(0)
                eSubject = Me.Subject.Text
                eBody = Me.Message.Text

                On Error Resume Next

                With OutMail
                    .To = Me.qry_Ryan_Emails.Work_Email
                    .CC = ""
                    .BCC = ""
                    .Subject = eSubject
                    .BodyFormat = olFormatHTML
                    .Display
                    .HTMLBody = eBody & vbCrLf & .HTMLBody
                    '.Send
                End With

                On Error GoTo 0
                Set OutMail = Nothing
                Set OutApp = Nothing


        End If

    End If
Next ctrl

End Sub
最后,将所有电子邮件收件人连接到一封电子邮件中,只发送一封电子邮件,而不是多封电子邮件,这是否更好?这可能是一个更好的方法。任何人有什么想法吗?

这对我很有用

Option Compare Database

Private Sub Command1_Click()

AllEmails = ""
For Each ctrl In Me.qry_Ryan_Emails.Controls

    If TypeName(ctrl) = "CheckBox" Then
        If ctrl.Enabled = True Then
            AllEmails = AllEmails & " " & Me!qry_Ryan_Emails.Form.Work_Email
        End If
    End If

Next ctrl

Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
    eSubject = Me!Subject
    eBody = Me!Message

    On Error Resume Next

    With OutMail
        .To = AllEmails
        .CC = ""
        .BCC = ""
        .Subject = eSubject
        .BodyFormat = olFormatHTML
        .Display
        .HTMLBody = eBody & vbCrLf & .HTMLBody
        .Send
    End With

    On Error GoTo 0
    Set OutMail = Nothing
    Set OutApp = Nothing

End Sub
此行将所有电子邮件连接成一个字符串

AllEmails = AllEmails & " " & Me!qry_Ryan_Emails.Form.Work_Email
然后我只向小组发送一封电子邮件

此链接对于引用窗体和子窗体上的控件非常有用


您可以使用列表框并在列表框中选择多个项目来执行基本相同的操作

Option Compare Database

Private Sub Command1_Click()
Dim varItem As Variant
Dim lngRow As Long
Dim strMsg As String

AllEmails = ""

With Me.List_Emails
    For lngRow = 0 To .ListCount - 1
        If .Selected(lngRow) Then
            AllEmails = AllEmails & .Column(2, lngRow)
        End If
    Next lngRow
End With


Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
    eSubject = Me!Subject
    eBody = Me!Message

    On Error Resume Next

    With OutMail
        .To = AllEmails
        .CC = ""
        .BCC = ""
        .Subject = eSubject
        .BodyFormat = olFormatHTML
        .Display
        .HTMLBody = eBody & vbCrLf & .HTMLBody
        '.Send
    End With

    On Error GoTo 0
    Set OutMail = Nothing
    Set OutApp = Nothing

End Sub