91 object variable problem

David b

Registered User.
Local time
Today, 14:59
Joined
Mar 2, 2003
Messages
102
I have an app running on a number of `puters in A97 with no problems.
Has been running fine on 1 A2000 machine. Put an upgrade on last night which didn`t alter anything in this part of the app and got -
91 object variable or with block variable not set - message. when running the
following
References seem Ok
Compiles OK
Other thing is some almost identical code - just a different rs - is still running OK.
Any thoughts ?
David B


code below -



Private Sub Command68_Click()
On Error GoTo Handler

If (Me!Textcount) = 0 Then
MsgBox "There are no records to send"
Exit Sub
Else
DoCmd.OpenQuery "bcmsdeletebirthtable", acNormal, acEdit
DoCmd.Close acQuery, "bcmsdeletebirthtable"
DoCmd.OpenQuery "bcmsbirths", acNormal, acEdit
DoCmd.Close acQuery, "bcmsbirths"
End If
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Dim strMessage As String
Dim strsubject As String
Dim strspareline As String
Set rs = db.OpenRecordset("BCMSREGgrab")

If Not rs.BOF And Not rs.EOF Then
rs.MoveFirst
Dim olObj As Outlook.Application

Dim olMail As Outlook.MailItem

Set olObj = New Outlook.Application

Set olMail = olObj.CreateItem(olMailItem)


Set olMail = olObj.CreateItem(olMailItem)



Do
strMessage = strMessage & vbCrLf & Trim(rs![Tag No] & Chr(124) & rs![DateOB] &
Chr(124) & rs![Sex] & Chr(124) & rs![Breeds] & Chr(124) & rs![electID] &
Chr(124) & rs![Dam I D] & Chr(124) & rs![surrdamid] & Chr(124) & rs![Ear Tag] &
Chr(124) & rs![Holding No] & Chr(124) & rs![birthherdsuffix] & Chr(124) &
rs![Holding No] & Chr(124) & rs![postherdsuffix]) 'data
strsubject = Trim(rs![BCMSapplicID] & Chr(124) & rs![BCMSVno] & Chr(124) &
rs![BCMSorigionater ID] & Chr(124) & rs.RecordCount & Chr(124) & rs![timestamp])
'header
strspareline = ""
rs.MoveNext



Loop Until rs.EOF



With olMail

.Subject = ""
.Body = strsubject & vbNewLine & strspareline & vbNewLine &
strMessage & vbNewLine
.To = "data@sis.defra.gsi.gov.uk"
.Send
End With
Set olMail = Nothing


End If

exitsub:

olObj.Quit
Set olObj = Nothing
rs.Close
Set rs = Nothing
Set db = Nothing
MsgBox "Email has been created. Open Outlook then press F5 to dial"



Dim stAppName As String

stAppName = "C:\Program Files\Microsoft Office\Office\outlook.exe"
Call Shell(stAppName, 1)
pbooClickTest = True
Exit Sub

Handler:
Select Case Err.number
Case Else
MsgBox Err.number & " " & Err.Description
Resume exitsub
End Select


End Sub
 
Which line of code produces the error?
 
Don`t no which line of code.
The problem system is a few miles away and I was hoping to have some clues before I went back to sort it out
David b
 
Ok. Have just read through the code again and think I might have found your problem.

You only dim olObj and olMail as part of the IF statement, but you have olObj.Quit and Set olObj = Nothing as part of the normal code.

So if there are no records, olObj will not have been dimensioned.

HTH,

Matt.
 

Users who are viewing this thread

Back
Top Bottom