Solved

add new records from querydef using openrecordset

Posted on 2014-04-07
8
512 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
Technology Partners: 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Many to Many From without subform 11 78
Access Criteria - Select first word from a string 27 63
Email question 19 85
MS Access Trouble With Grouping and Suming Query Results 6 47
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
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…

738 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