?
Solved

Object variable or with block variable not set

Posted on 2001-06-13
7
Medium Priority
?
234 Views
Last Modified: 2008-03-06
I am trying to use a qry as a recordsource.  The qry uses a query(qryVATLett) based on 2 tables + 2 other tables.  I think I am getting this error message because of the query.  Any ideas?

Sicando


Dim rpt As Report, rst As Recordset, db As Database, rst1 As Recordset, strSQL As String
Dim strQry As String
Dim strDate1 As Date, strDate2 As Date

strDate1 = Forms!frmreports!txtDate1
strDate2 = Forms!frmreports!txtDate2

strSQL = "SELECT tblMember.ReferenceNo, qryVATlett.AccountName, qryVATlett.AccountNumber," _
        & " qryVATlett.SortCode, tblMember.FinalAcceptance, tblMember.FrequencyofPayment," _
        & " tblMember.MethodofPayment, tblMember.RenewalDate, qryVATlett.Bank," _
        & " qryVATlett.Address1, qryVATlett.Address2, qryVATlett.Address3," _
        & " qryVATlett.Town, qryVATlett.County, qryVATlett.Postcode, " _
        & " tblSubscriptionDetails.NetSubscription" _
        & " FROM (tblMember INNER JOIN qryVATlett ON tblMember.ReferenceNo = qryVATlett.ReferenceNo) INNER JOIN tblSubscriptionDetails ON tblMember.LevelofMembership = tblSubscriptionDetails.SubscriptionRef" _
        & " WHERE (tblMember.FrequencyofPayment = 'A') AND (tblMember.MethodofPayment = 3)" _
        & " AND tblMember.RenewalDate Between #" & Format(strDate1, "mm\/dd\/yyyy") & "# And #" & Format(strDate2, "mm\/dd\/yyyy") & "#" _
        & " AND (qryVATlett.Bank Is Not Null) AND tblMember.Status In ('LM1','LM2','LM3)" _
        & " ORDER BY qryVATlett.Bank"

rpt.RecordSource = strSQL
0
Comment
Question by:sicando
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 2

Expert Comment

by:gregdavey
ID: 6185395
Nah. You are getting the error becuase you have not set the report to anything

I have a code called Company. Here is my code

    Dim rpt As Report
    DoCmd.OpenReport "Company", acViewPreview
    Set rpt = Reports("Company")
    rpt.RecordSource = strSQL

See how that goes!

Greg
0
 
LVL 8

Accepted Solution

by:
dovholuk earned 200 total points
ID: 6185835
greg is right. where is this code that is running. is it on the report that is opening? is it behind a button? where is it?

as Greg points out, you never set the report variable (rpt) to anything. you need to set rpt = to the report you are trying to open, but depending on where your code is located there are different ways to do it.

i don't think greg's code will work for you though, as his idea is to open the report in preview mode first. if you do this, THEN set the recordsource, the report won't requery.

i think that you should move your code to the On Open event of your report. then, simply change your

rpt.RecordSource = strSQL

to

Me.RecordSource = strSQL

enjoy
dovholuk
0
 

Author Comment

by:sicando
ID: 6186231
Dough!  SQL was wrong as well

Okay
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
LVL 8

Expert Comment

by:dovholuk
ID: 6186278
i've never gotten a c before...

for my benefit, how could i have given you a better answer?

thanks for helping me out,

dovholuk
0
 

Author Comment

by:sicando
ID: 6186362
Guess I'm just a bit pissed off. I thought the problem was in the SQL, which it was.

Give yourself a A+ if it makes you feel better

Thanks for your help
0
 

Author Comment

by:sicando
ID: 6187189
Guess I'm just a bit pissed off. I thought the problem was in the SQL, which it was.

Give yourself a A+ if it makes you feel better

Thanks for your help
0
 
LVL 2

Expert Comment

by:gregdavey
ID: 6189223
So, could you please post the code that worked ok?

Thanks!

Greg
0

Featured Post

How Blockchain Is Impacting Every Industry

Blockchain expert Alex Tapscott talks to Acronis VP Frank Jablonski about this revolutionary technology and how it's making inroads into other industries and facets of everyday life.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question