Solved

Object variable or with block variable not set

Posted on 2001-06-13
7
227 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
  • 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 100 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

947 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now