Solved

add new records from querydef using openrecordset

Posted on 2014-04-07
8
505 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 36

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 36

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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
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 36

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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Suggested Solutions

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

820 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