Solved

Object variable or with block variable not set

Posted on 2001-06-13
7
229 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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

820 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