2013-12-09 3 views
1

자동 이메일 전송을위한 개인 서브 기능 코드가 있습니다. 나는 아래의 코드를 사용하여 함수에 자신을 설정하는 시도에 기대어 피트의 코드자동 이메일 기능

ACCESS 2007 - Automatically Send and Email Using Outlook Upon a Specific Event

을 공급. 그러나 그것은 작동하지 않습니다. 내가 완전히 잘못 설정했다는 느낌이 들었다. 또한 가능한 경우 전체 기록 정보가 포함되도록 전자 메일 본문을 원합니다.

Option Explicit 
Public Started As Boolean 
Public oApp As Outlook.Application 
Public oItem As Outlook.MailItem 
Function AutoEmail() 



'Automatic Email to send notifications to selected user 
If Combo99.Text = "SM" Or "TW" Or "LM" Or "LV" Or "SV" Then 


    On Error Resume Next 
    'Get Outlook if it's running 
    Set oApp = GetObject(, "Outlook.Application") 
    If Err <> 0 Then 
     'Outlook wasn't running, start it from code 
     Set oApp = CreateObject("Outlook.Application") 
     Started = True 
    End If 

        Set oItem = oApp.CreateItem(olMailItem) 
        With oItem 
         .To = "[email protected]" 
         .Subject = "AutoEmail Test" 
         .Body = "Please enjoy this complimentary email. If this worked please email back." 
         'Send the email 
         .Send 
        End With 

            Set oItem = Nothing 
            If Started Then 
             oApp.Quit 
            End If 

'Display message to the user 
MsgBox "A model that is on the watch list has been selected. An Automatic Email has been sent", vbOKOnly, AutoEmail 

Else 
     'Do nothing 
End If 


End Function 
+0

IF 문을 삭제하면 양식이 제출 될 때 필요합니다. Combo99 (곧 변경 될 예정 임)는 더 이상 지원되지 않는 모델을 확인해야하는 곳입니다. – ASM2701

답변

1

이 코드 라인 두 가지 문제 ...가 있습니다

If Combo99.Text = "SM" Or "TW" Or "LM" Or "LV" Or "SV" Then 
  1. 포커스가있을 경우에만 콤보의 Text 속성을 사용할 수 있습니다

    . 사용자가 명령 단추를 클릭 할 때와 같이 다른 컨트롤로 포커스가 이동하면 대신 Combo99.Value을 사용하십시오.

  2. 조건간에 Or을 사용하는 경우 각에 대해 = 부호의 왼쪽에서 항목을 다시 반복해야합니다.

If strLetter = "a" Or "b" Then 
If strLetter = "a" Or strLetter = "b" Then 

첫 번째

오류가 발생합니다 ...이 두 If 문을 고려하지만, 두 번째는하지 않습니다.

값 목록과 비교하려는 경우 Select Case을 사용할 수 있습니다.

Select Case Me.Combo99.Value 
Case "SM", "TW", "LM", "LV", "SV" 
    ' insert code to send email 
Case Else 
    ' no email 
End Select 
+0

빠른 응답을 주셔서 감사합니다 Hans ... 내가 코드를 실행하려고하면 ME의 사용이 유효하지 않은 컴파일 오류가 발생합니다. – ASM2701

+0

그런 다음 "나"를 버리면 어떻게됩니까? – HansUp

+0

다음과 같은 오류 메시지가 나타납니다. 컴파일 오류 : 변수가 정의되지 않았습니다. – ASM2701