Solved

Object variable or with block variable not set

Posted on 2001-06-13
7
231 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 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
find first method with 2 variable search criteria 10 44
MS Excel Pivot Table and MS Access Pivot Table 4 75
Menus 6 52
Combo box question 6 51
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
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.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

737 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