Login or Sign up Help | Site Map
Connecting Tech Pros Worldwide

Recordset "Object variable or With Block variable not set"

Question posted by: nspader (Member) on March 27th, 2008 08:01 PM
I want to start out saying I am a novice code writer. I am trying to send a report via email based on each supplier. The code below is what I am using. I need to base recordset on Form, report generated is based on the supplier number on that form so as to only create a single report.

This is Access 2000, with Windows 2000

Code: ( text )
  1. Private Sub EMAIL_Click()
  2. On Error GoTo Err_EMAIL_Click
  3.  
  4.     DoCmd.OpenForm "Email", acNormal
  5.    
  6.     Dim rst As DAO.Recordset
  7.     Dim stDocName As String
  8.     Dim strSendTo As String
  9.     Dim strSubject As String
  10.     Dim strMessageText As String
  11.    
  12.     Set rst = Me.Recordset
  13.    
  14.     Do While rst.EOF = False
  15.         stDocName = "Request for Updated PO Info EMAIL"
  16.         strSendTo = [Report_Request for Updated PO Info EMAIL].Supplier_Email
  17.         strSubject = "Wesco Distribution Shipping Update Report"
  18.         strMessageText = "To:  " & [Report_Request for Updated PO Info EMAIL].Supplier_Contact_Name & vbCrLf _
  19.             & "" & vbCrLf _
  20.             & "Attached is a Shipping Update Report for certain PO numbers." & vbCrLf _
  21.             & "" & vbCrLf _
  22.             & "Please review the attached report and reply back to this email with the requested information." & vbCrLf _
  23.             & "" & vbCrLf _
  24.             & "Thank you," & vbCrLf _
  25.             & "" & vbCrLf _
  26.             & "Wesco Distribution Expediting Department "
  27.    
  28.         DoCmd.SendObject acSendReport, stDocName, acFormatRTF, strSendTo, , , strSubject, strMessageText
  29.    
  30.     rst.MoveNext
  31.    
  32.     Loop
  33.    
  34.     rst.Close
  35.    
  36.     Set rst = Nothing
  37.    
  38.     DoCmd.Close acForm, "Email", acSaveYes
  39.    
  40. Exit_EMAIL_Click:
  41.     Exit Sub
  42.  
  43. Err_EMAIL_Click:
  44.     MsgBox Err.Description
  45.     Resume Exit_EMAIL_Click
  46.    
  47. End Sub


It is throwing error "Object variable or With Block variable not set"

The error happens on "Do While rst.EOF = False"

Any Help here is greatly appreaciated.

NICK
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
Stewart Ross Inverness's Avatar
Stewart Ross Inverness
Forum Leader
717 Posts
March 27th, 2008
08:09 PM
#2

Re: Recordset "Object variable or With Block variable not set"
Hi Nick. I think your problem is at line 12, which I guess should be referring to the RecordsetClone property to copy the underlying recordset from your form:

Set rst = Me.Recordsetclone

The object error is arising because there is no valid current recordset in object variable rst.

-Stewart

Reply
nspader's Avatar
nspader
Member
64 Posts
March 28th, 2008
01:06 PM
#3

Re: Recordset "Object variable or With Block variable not set"
Thank you.

I made that change and now it is throwing error stating "You entered and expression that has an invalid reference to the RecordsetClone Property"

**Note: The form I am using has a subform located in it. I dont know if this is part of the problem.

Any help is greatly appreciated.

Nick

Reply
aprpillai's Avatar
aprpillai
Newbie
13 Posts
March 28th, 2008
02:38 PM
#4

Re: Recordset "Object variable or With Block variable not set"
Pardon me if I am wrong, I don't see anywhere in your code you are referencing the rst object for picking the field values.

For example :

strSendTo = [Report_Request for Updated PO Info EMAIL].Supplier_Email

must be written as

strSendTo = rst![Report_Request for Updated PO Info EMAIL].Supplier_Email

or

With rst
strSendTo = .[Report_Request for Updated PO Info EMAIL].Supplier_Email
.
.
End with

isn't it. Need change in other statements also.

Reply
nspader's Avatar
nspader
Member
64 Posts
March 28th, 2008
04:08 PM
#5

Re: Recordset "Object variable or With Block variable not set"
I am not sure if that is true.

However, it stops before it gets to that point. The error occurs at rst = ...

I believe that code works in order, please correct if I am wrong.

Nick

Reply
nspader's Avatar
nspader
Member
64 Posts
March 28th, 2008
06:12 PM
#6

Re: Recordset "Object variable or With Block variable not set"
Also, the str= is pulling from the report not from the recordsource....should i have it pull from the recorsource instead?

Reply
aprpillai's Avatar
aprpillai
Newbie
13 Posts
March 28th, 2008
06:39 PM
#7

Re: Recordset "Object variable or With Block variable not set"
If you are trying to move the record on the Form one by one with the use of the Recordsetclone and use the Cureent record field on the Form as criteria for the Report to send the Mail then you have to Synchronize the BookMark of the Recordsetclone with the Form's Bookmark. Try the following
Code: ( text )
  1. Dim bkMark as string
  2.  
  3. Do while rst.EOF = false
  4.     bkMark = rst.BookMark
  5.     Me.BookMark = bkMark ' this will Synchronize the record
  6. .
  7. .
  8. .
  9. rest of your program
  10.  
  11.  
  12. rst.moveNext
  13. Loop

Reply
Stewart Ross Inverness's Avatar
Stewart Ross Inverness
Forum Leader
717 Posts
March 28th, 2008
08:59 PM
#8

Re: Recordset "Object variable or With Block variable not set"
Hi again. The more I look at your code the more I [font=Verdana][size=2]think that you should reconsider what it is you are trying to achieve and start again. Aprpillai is right that you are not actually referring to the rst elements (although as you have said you are getting an error message before any of these lines is reached). I think it is actually report elements you may be referring to in the parts that Aprpillai has identified. There are so many difficulties and apparent misunderstandings I think it is not practicable to resolve them this way.[/size][/font]

You are opening a form called e-mail at the top of your code. In what form is your current code located? I suspect you are getting the recordset clone error because the 'me' property is referring to whatever form the subroutine is in, not to your e-mail form at all. Is your current form some form of switchboard that is unbound? This would at least explain why recordsetclone is causing an error.

Rather than go line by line into the many errors that are now apparent, please tell us in the broad what it is you are doing, which queries are involved in doing so, what report you run, how you propose to filter it for each person you are e-mailing, what format you propose to e-mail the report in (snapshot, rtf, Excel etc), and how you get the e-mail addresses for each person. Maybe then we can give better advice that will actually help you to achieve your goal.

Regards

Stewart

Reply
nspader's Avatar
nspader
Member
64 Posts
March 31st, 2008
04:08 PM
#9

Re: Recordset "Object variable or With Block variable not set"
Thank you for that Infomation.

I did infact have it posted off the wrong form. I have changed it to perform on form load of the correct form and it works.

Now, I have a different problem. Now it only loops through 3 records, not all records in the recordset.

I am going to post under new heading. Thank you for your help. Please look for new heading if you know anything about sendobject and loops.

Nick

Reply
NeoPa's Avatar
NeoPa
Admin
9,607 Posts
April 6th, 2008
10:40 PM
#10

Re: Recordset "Object variable or With Block variable not set"
Rather than them looking for it Nick, you could post a link to it in here and that way get a higher likelihood of it being seen by any already interested parties ;)

Reply
nspader's Avatar
nspader
Member
64 Posts
April 7th, 2008
04:33 PM
#11

Re: Recordset "Object variable or With Block variable not set"
Absolutely here is the link

SendObject Loop does not loop through all records!!

Thank you

Reply
Reply
Not the answer you were looking for? Post your question . . .
169,970 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Top Microsoft Access / VBA Forum Contributors