无法找出正在声明的不是SET的对象 [英] Can't figure out what object is being declared that is not SET
问题描述
我在Access VBA脚本中遇到错误,提示错误#91:未设置对象变量或With块变量.我在MSDN网站上进行了搜索,并找到了引用一个>.它说我有一个声明为不是SET
的对象,或者我有一个不是SET
的WITH
块变量.好像我的脚本中没有WITH
块一样,它必须是第一个.但是,对于我仍然相当幼稚的眼睛,我正在设置我正在使用的所有对象.有人可以帮我弄清楚这个错误吗?
I'm getting an error in my Access VBA script that says Error # 91: Object variable or With block variable not set. I searched on the MSDN site and found the reference. It says that I either have an object declared that isn't being SET
or that I have a WITH
block variable not SET
. Seeing as how I don't have a WITH
block in my script, it must be the first one. But to my still rather naive eyes I am setting all the objects that I'm using. Could someone help me figure out this error?
侧面任务:我是否在正确处理错误?我添加了If
语句,因为它每次都会给出0
的错误消息,所以我这样做是为了仅显示Err.Number > 0
发生的情况.
Side quest: Am I doing error handling correctly? I added that If
statement because it was giving an error message of 0
every time, so I made it so that it only shows if an Err.Number > 0
happens.
Private Sub Form_Timer()
On Error GoTo ErrorHandler
current_date_time = Now
If current_date_time = #6/28/2016 8:18:15 AM# Then
MsgBox ("the current_date_time variable holds: " & current_date_time)
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim qdf As DAO.QueryDef
Dim mail_body As String
Dim oApp As Outlook.Application
Dim oMail As MailItem
mail_body = "The following jobs...blah...blah..." & vbCrLf
Set dbs = CurrentDb
Set qdf = dbs.QueryDefs("qry_BMBFLoc")
Set rst = qdf.OpenRecordset
If Not (rst.EOF And rst.BOF) Then
rst.MoveFirst
Do Until rst.EOF = True
mail_body = mail_body & rst!job & "-" & rst!suffix & vbCrLf
rst.MoveNext
Loop
End If
rst.Close
dbs.Close
Set rst = Nothing
Set oMail = oApp.CreateItem(olMailItem)
oMail.Body = mail_body
oMail.Subject = "Blah blah"
oMail.To = "someone@someplace.com"
oMail.Send
Set oMail = Nothing
Set oApp = Nothing
End If
ErrorHandler:
If (Err.Number > 0) Then
MsgBox ("Error #: " & Err.Number & vbCrLf & vbCrLf & Err.Description)
End If
End Sub
推荐答案
首先,我将显示以下行:
Firstly, I would have the following line:
dim oMail as outlook.mailItem
然后,您需要先设置OApp
,然后再设置oMail
:
You then need to set OApp
before you set the oMail
:
Set oApp = CreateObject("Outlook.application")
如果您发现自己在发送操作中遇到运行时错误287,请在此处查看我的帖子.
If you find yourself getting run-time error 287 on the send action, see my post here.
我将使用的标准错误处理程序如下:
A standard error handler I would use, is like so:
errHandler:
Dim msg As String
If Err.Number <> 0 Then
msg = "email Form Timer Error #" & Str(Err.Number) & " error Line: " & Erl & Chr(13) & Err.Description
MsgBox msg, , "Error", Err.HelpFile, Err.HelpContext
End If
Exit Sub
这篇关于无法找出正在声明的不是SET的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!