Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Max Query Length - MS Access 2000

Posted on 2004-04-02
11
Medium Priority
?
1,202 Views
Last Modified: 2012-06-21
Hi, I am dynamically generating a query using VBA in MS Access. When I use that query to set the recordsource property of my form/report, I get error "2176" on runtime saying that the setting for recordsource property is too long. As per my knowledge, the max. allowed length for recordsource property is 2048, but my query length is more than that. What can be done in this case? Plz help. (I had an idea of dynamically generating some table and setting the recordsource as that table. But again, maximum query length will come into picture while inserting the data in new table)
0
Comment
Question by:janmejay_bhatt
[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
  • 4
  • 2
  • 2
  • +1
11 Comments
 

Author Comment

by:janmejay_bhatt
ID: 10745466
Hi, I am dynamically generating a query using VBA in MS Access. When I use that query to set the recordsource property of my form/report, I get error "2176" on runtime saying that the setting for recordsource property is too long. As per my knowledge, the max. allowed length for recordsource property is 2048, but my query length is more than that. What can be done in this case? Plz help. (I had an idea of dynamically generating some table and setting the recordsource as that table. But again, maximum query length will come into picture while inserting the data in new table)
0
 
LVL 34

Accepted Solution

by:
Mike Eghtebas earned 1000 total points
ID: 10745943
In OnOpen event of your report include:

me.RecordSource=fnMyReport

-----
In a standard module, include:

Function fnMyReport() As String

'    fnMyReport=... build your SQL, don't use table names where not necessary or use alia names like
'                       Select A.Name From tEmplyee A Order By Name
End If
0
 
LVL 18

Expert Comment

by:Data-Man
ID: 10748008
I totally agree with eghtebas...I ran into the same problem....Make sure you Alias all your table names in your SQL

0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 18

Expert Comment

by:Data-Man
ID: 10748013
SELECT a.LastName, a.FirstName, b.Field3 FROM tblEmployees a JOIN tblTable2 b ON b.ID = a.ID ORDER BY a.LastName, a.FirstName
0
 
LVL 54

Assisted Solution

by:nico5038
nico5038 earned 1000 total points
ID: 10748047
A workaround will be to store the query's SQL and base the form on the query instead of the SQL string.
Just use in the form's OnOpen event:

dim qd as dao.querydef

set qd = currentdb.querydefs("qryFormXdanamic")
qd.SQL = <generated string>

And make sure the form's source is set to qryFormXdanamic

That's all.

Nic;o)
0
 
LVL 18

Expert Comment

by:Data-Man
ID: 10752403
Taking what nic;o) said one step further you could keep the creation of your SQL statement dynamic in the open event, but append it to the querydefs collection to get around the 2048 limitation.

      Dim strSQL As String
      Dim qdefTemp as DAO.QueryDef

      strSQL = "Your huge SQL statement here"
      Set qdfTemp = CurrentDb.CreateQueryDef("qselTempForReport",strSQL)
 
      Make sure to set the record source of the form to the new query - qselTempForReport

Mike

0
 

Author Comment

by:janmejay_bhatt
ID: 10762091
Hi,

Thank you all for your suggestions.

I implemented what "eghtebas" suggested. That solved problem for one of the reports, but could not solve for another report with longer SQL. I think what the process mentioned by "eghtebas" does is to reduce the length of SQL as a whole using aliases like "a", "b" etc... So, it worked for my report with smaller query.

I tried to use "DAO.QueryDef" in the project as suggested by "nico5038" and "Data-Man". I think this should work as I solved a similar problem of longer query by creating a query in query builder and then setting recordset to that query. The problem I am facing here in MS Access module is that when I type "." after DAO, I do not get dropdown list of its properties. May be DAO is not installed in project. Can anyone tell how to install it so that I can use it in my MS Access module? (I installed MDAC 2.8 and also registered "dao360.dll" using "RegSvr32", but still it did not work.) I saw the dropdown list of "More Controls" in project, but I could not find anything like DAO or Data Access Objects or Microsoft DAO/Data Access Objects.

Can anyone suggest the solution?

Thanks,
JJ
0
 
LVL 18

Expert Comment

by:Data-Man
ID: 10762119
You will need to set a reference to the DAO Object Library

In the VB Editor
Tools | Refereneces

scroll down until you see Microsoft DAO 3.6 Object Library and place a check in the little box.

Mike


0
 
LVL 54

Expert Comment

by:nico5038
ID: 10767136
Also other versions of DAO will work, no need for DAO 3.6 specifically.

Nic;o)
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
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…

721 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