Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.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

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
Vba 从Microsoft Outlook在Microsoft Access中运行附加查询时缺少字段_Vba_Ms Access_Outlook - Fatal编程技术网

Vba 从Microsoft Outlook在Microsoft Access中运行附加查询时缺少字段

Vba 从Microsoft Outlook在Microsoft Access中运行附加查询时缺少字段,vba,ms-access,outlook,Vba,Ms Access,Outlook,目标: 在Microsoft Outlook中,我想运行位于Microsoft Access数据库中的追加查询,该查询将在“日志”表中创建记录,其中包含有关已发送电子邮件的信息。(追加由事件“Application_ItemSend”触发) 问题: 当我运行查询时,Access只附加了七个字段中的两个:变量“strSenderEmail”和函数“now()”,这两个字段插入到查询->中,我的意思是在表“Log”中,我只有关于发送者和日期的信息,但主题、接收者等都是空的 其他信息: -参数名称->

目标:
在Microsoft Outlook中,我想运行位于Microsoft Access数据库中的追加查询,该查询将在“日志”表中创建记录,其中包含有关已发送电子邮件的信息。(追加由事件“Application_ItemSend”触发)

问题:
当我运行查询时,Access只附加了七个字段中的两个:变量“strSenderEmail”和函数“now()”,这两个字段插入到查询->中,我的意思是在表“Log”中,我只有关于发送者和日期的信息,但主题、接收者等都是空的

其他信息:
-参数名称->我没有信息表明有错误或缺失的内容
-所有参数均输入
-我尝试通过参数替换:“qdf.parameters(1)=test”,但不起作用
-如果我从access运行此查询并“从手”插入参数,则一切正常

问题:
为什么我的查询没有正确追加?
或者,我将尝试使用SQL命令插入数据或将记录集添加到表中

功能代码:

strBackendPath - path of backend access
Qapp_001 - name of the append query in access

Set dbs = DBEngine.OpenDatabase(strBackendPath) 'set connection with backend 
Set qdf = dbs.QueryDefs(Qapp_001)               'set update merged processes query 
<br>
qdf![strSenderEmail] = GetOriginalSenderAddress(objMailItem)  'this is external function, this variable is actually working properly -> information are added in new record
qdf!strReceiverEmail = "test1"      'insert receiver 
qdf!strSubject = "test2"            'subject of the e-mail 
qdf!struserUID = "test3"            '(Environ$("Username"))         
qdf!bytCommunicationType = 1        'define type of communication 
qdf!bytStatus = 1                   'define status

qdf.Execute                         'run append query 
<br>
Set qdf = Nothing   'clear query 
Set dbs = Nothing   'clear database 
    PARAMETERS 
strSenderEmail LongText, strReceiverEmail LongText, strSubject LongText, struserUID Text ( 255 ), bytCommunicationType Byte, bytStatus Byte;    
    INSERT INTO 
Tbl_02_Log ( SenderEmail, ReceiverEmail, Subject, PreparationDateAndTime, userUID, CommunicationType, Status )
    SELECT 
[strSenderEmail] AS Expr1, [strReceiverEmail] AS Expr2, [strSubject] AS Expr3, Now() AS Expr4, [struserUID] AS Expr5, [bytCommunicationType] AS Expr6, [bytStatus] AS Expr7;
追加查询的SQL代码(从Access):

strBackendPath - path of backend access
Qapp_001 - name of the append query in access

Set dbs = DBEngine.OpenDatabase(strBackendPath) 'set connection with backend 
Set qdf = dbs.QueryDefs(Qapp_001)               'set update merged processes query 
<br>
qdf![strSenderEmail] = GetOriginalSenderAddress(objMailItem)  'this is external function, this variable is actually working properly -> information are added in new record
qdf!strReceiverEmail = "test1"      'insert receiver 
qdf!strSubject = "test2"            'subject of the e-mail 
qdf!struserUID = "test3"            '(Environ$("Username"))         
qdf!bytCommunicationType = 1        'define type of communication 
qdf!bytStatus = 1                   'define status

qdf.Execute                         'run append query 
<br>
Set qdf = Nothing   'clear query 
Set dbs = Nothing   'clear database 
    PARAMETERS 
strSenderEmail LongText, strReceiverEmail LongText, strSubject LongText, struserUID Text ( 255 ), bytCommunicationType Byte, bytStatus Byte;    
    INSERT INTO 
Tbl_02_Log ( SenderEmail, ReceiverEmail, Subject, PreparationDateAndTime, userUID, CommunicationType, Status )
    SELECT 
[strSenderEmail] AS Expr1, [strReceiverEmail] AS Expr2, [strSubject] AS Expr3, Now() AS Expr4, [struserUID] AS Expr5, [bytCommunicationType] AS Expr6, [bytStatus] AS Expr7;
总而言之。 我没有找到运行内置access追加查询而不出错的解决方案

我编写了一个使用数据库引擎运行的SQL代码,其中有一些全局/私有变量,但解决方案的思路如下:

Dim dbe As Object                       'dao database
Dim dbs As Object                       'access database with actual data
Dim strSender As String                 'address of group mail, from which e-mail is being sent
Dim strReceiver As String               'consolidated string of recipients: To + CC + Bcc
Dim strSubject As String                'subject of sent e-mail
Dim strUID As String                    'uid of the user who sent e-mail
Dim strSQL As String                    'SQL code of append query, which adds new log record to database

Set dbe = CreateObject("DAO.DBEngine.120")  'version on win7 and win10 is 3.6
Set dbs = dbe.OpenDatabase(GC_BackendPath, False, False, ";pwd=" & GC_Password & "") 'set connection with backend

strSender = "'" & G_OriginalSender & "'"        'get sender e-mail - group mailbox
strReceiver = G_MailReceiver                    'assign recipient list
strSubject = G_MailSubject                      'assign subject of email

strUID = "'" & CreateObject("wscript.Network").UserName & "'"   'get user UID and assign under variable

strSubject = "'" & Replace(Mid(strSubject, 2, Len(strSubject) - 2), "'", "") & "'"
strSQL = "INSERT INTO " & Tbl_02 & " ( SenderEmail, ReceiverEmail, Subject, PreparationDateAndTime, userUID, CommunicationType, Status) SELECT " & strSender & " AS SenderEmail, " & strReceiver & " AS ReceiverEmail, " & strSubject & " AS Subject, Now() AS PreparationDateAndTime, " & strUID & " AS userUID, " & bytCommunication & " AS CommunicationType, " & bytStatus & " AS Status;"

Set dbs = dbe.OpenDatabase(GC_BackendPath)      'set database which will be updated with new record log

dbs.Execute strSQL                              'run SQL code for given database
dbs.Close                                   'close database
Set dbs = Nothing
总而言之。 我没有找到运行内置access追加查询而不出错的解决方案

我编写了一个使用数据库引擎运行的SQL代码,其中有一些全局/私有变量,但解决方案的思路如下:

Dim dbe As Object                       'dao database
Dim dbs As Object                       'access database with actual data
Dim strSender As String                 'address of group mail, from which e-mail is being sent
Dim strReceiver As String               'consolidated string of recipients: To + CC + Bcc
Dim strSubject As String                'subject of sent e-mail
Dim strUID As String                    'uid of the user who sent e-mail
Dim strSQL As String                    'SQL code of append query, which adds new log record to database

Set dbe = CreateObject("DAO.DBEngine.120")  'version on win7 and win10 is 3.6
Set dbs = dbe.OpenDatabase(GC_BackendPath, False, False, ";pwd=" & GC_Password & "") 'set connection with backend

strSender = "'" & G_OriginalSender & "'"        'get sender e-mail - group mailbox
strReceiver = G_MailReceiver                    'assign recipient list
strSubject = G_MailSubject                      'assign subject of email

strUID = "'" & CreateObject("wscript.Network").UserName & "'"   'get user UID and assign under variable

strSubject = "'" & Replace(Mid(strSubject, 2, Len(strSubject) - 2), "'", "") & "'"
strSQL = "INSERT INTO " & Tbl_02 & " ( SenderEmail, ReceiverEmail, Subject, PreparationDateAndTime, userUID, CommunicationType, Status) SELECT " & strSender & " AS SenderEmail, " & strReceiver & " AS ReceiverEmail, " & strSubject & " AS Subject, Now() AS PreparationDateAndTime, " & strUID & " AS userUID, " & bytCommunication & " AS CommunicationType, " & bytStatus & " AS Status;"

Set dbs = dbe.OpenDatabase(GC_BackendPath)      'set database which will be updated with new record log

dbs.Execute strSQL                              'run SQL code for given database
dbs.Close                                   'close database
Set dbs = Nothing

不确定这是否是主要问题,但
LongText
参数实际上不起作用。见和。我会使用
记录集。AddNew
而不是参数化的插入查询。我同意Andre的观点,最好使用记录集插入。您还可以尝试取消显式参数声明,让DB引擎自动确定类型。参数类型是一个难题,因为有许多同义词模式,它们彼此不兼容。作为替代方案,您可以尝试使用
Memo
交换
LongText
。不确定这是否是主要问题,但
LongText
参数实际上不起作用。见和。我会使用
记录集。AddNew
而不是参数化的插入查询。我同意Andre的观点,最好使用记录集插入。您还可以尝试取消显式参数声明,让DB引擎自动确定类型。参数类型是一个难题,因为有许多同义词模式,它们彼此不兼容。或者,您可以尝试将
长文本
备忘录
交换。