Solved

Object variable or with block variable not set

Posted on 2001-06-13
7
225 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

758 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

17 Experts available now in Live!

Get 1:1 Help Now