Solved

add new records from querydef using openrecordset

Posted on 2014-04-07
8
518 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
[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
  • 5
  • 3
8 Comments
 
LVL 37

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 37

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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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 37

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

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

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.
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
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.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

691 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