Solved

add new records from querydef using openrecordset

Posted on 2014-04-07
8
498 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
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.
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 …

743 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

13 Experts available now in Live!

Get 1:1 Help Now