Solved

add new records from querydef using openrecordset

Posted on 2014-04-07
8
499 Views
Last Modified: 2014-04-23
Hi i am having a query what i need to open with querydef as it has several parameters, then i want to make a table with the results, i don't know where i am starting , so basically the question is if i can fetch records from the querydef object after setting the parameters

Thanks in advance
0
Comment
Question by:yidel718
  • 5
  • 3
8 Comments
 
LVL 34

Accepted Solution

by:
PatHartman earned 500 total points
ID: 39983436
The basic code to open a DAO recordset for a query with parameters is:
Dim db as DAO.Database
Dim qd as DAO.Querydef
Dim rs as DAO.Recordset

Set db = Currentdb()
set qd = db.Querydefs!yourqueryname
    qd.Parameters!parm1 = Me.parm1
    qd.Parameters!parm2 = Me.parm2
    qd.Parameters!parm3 = Me.parm3
Set rs = qd.Openrecordset

Do until rs.EOF = True
    ....
    rs.MoveNext
Loop

Open in new window


But - rather than use a code loop to create the table, why not create a make-table query that runs your select query?
0
 
LVL 1

Author Comment

by:yidel718
ID: 39983506
thanks,
using Access Query MakeTable runs Slow
0
 
LVL 34

Expert Comment

by:PatHartman
ID: 39983559
If the make table runs slowly, VBA is not likely to improve it.  You're just adding an additional layer of logic and processing.  The problem is most likely with the underlying query.  

Compact and repair the database to clear out the debris.  Then examine the joins and selection criteria for the query to see if they might benefit by adding indexes to the tables.
0
 
LVL 1

Author Comment

by:yidel718
ID: 39983573
How can i add all results at once to the table, without prompting the parameters, or atleast the whole RS without looping every field
0
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 1

Author Comment

by:yidel718
ID: 39983607
per my experience when i used the actual query for the Recordsource it didn't take that much time to show the results, so i am suspecting the makeTable, but DDl i believe makes it much faster ( i wouldn't argue as you are more experienced than me, but i am trying to do the best performance for the application )
0
 
LVL 1

Author Comment

by:yidel718
ID: 39983614
BTW how many times a day do i need to compact the DB ?
0
 
LVL 1

Author Comment

by:yidel718
ID: 39983676
now i got a better excuse why to use Create Table rather than Make-Table, because the joined tables has 2 Auto number fields and cannot be created with make table (good excuse ??)
0
 
LVL 34

Expert Comment

by:PatHartman
ID: 39984272
How can i add all results at once to the table, without prompting the parameters, or atleast the whole RS without looping every field
I don't understand the question.  I posted sample code to supply the parameters.  You won't get prompted, the query will simply fail if you run it this way and don't supply parameters.


Why do you need to make the temp table at all.  Temp tables are usually not necessary since in Access, select queries and tables are interchangeable for most purposes so just use the selection query rather than the temp table.
per my experience when i used the actual query for the Recordsource it didn't take that much time to show the results
Access fools us by opening a form or table or query as soon as it has enough rows to populate it.  Access then continues fetching data in the background.
BTW how many times a day do i need to compact the DB ?
Experience will tell you.  It really depends on how large the temp tables are and how frequently you recreate them.  Access doesn't reuse work space.  

Where is the data coming from?  Is the BE Jet/ACE or SQL Server or something else?  Are you the only user?
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

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

932 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

10 Experts available now in Live!

Get 1:1 Help Now