Creating a Temp Table in MS Access

Amazing Experts!

I'm stuck.  I combined a bunch of tables into a union query and am trying to dump that query back into a table so I can add a checkbox field and make the query "editable" so to speak.  The problem is that the query has 5000+ records, but when I run the code, I only end up with 200+ records in the blank table.  I'm not getting an error message and I back checked that my blank table has the correct amount of fields.  (Note: I can't upload the database since it is client confidential, but I can generalize the content.)

I used this vba/SQL code in the OnLoad event of the form:
CurrentDb.Execute "INSERT INTO TBL_Blank  (Field1, Field2, Field3 ...)
SELECT Field1, Field2, Field3 ... FROM QRY_CombinedRecords;", dbFailOnError

Should I be using DAO.Database (see mwolfe02 response)?
http://stackoverflow.com/questions/6843017/how-to-insert-entire-dao-recordset-into-a-table-with-vba

or recordset (see Gord Thompson response).


I'm not sure why it doesn't just copy the 5,000+ records in the query and pastes them in the blank table I set up.

Any ideas?
TechNinja2Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dale FyeOwner, Developing Solutions LLCCommented:
does your temporary table have a primary key or unique index values?  Generally, the dbFailOnError syntax will ensure you get an error message if the entire recordset cannot be appended to the table.

Does the SELECT query contain more than one field which is a primary key (autonumber) field?  Is the corresponding field in the temp table an autonumber or Long Integer (it should be a long integer).
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
John TsioumprisSoftware & Systems EngineerCommented:
Why don't you make a passthrough query to select the records and use Access Query Designer to create a "Make Table Query" ...if something is wrong it should popup
0
Helen FeddemaCommented:
Instead of creating the temp table from scratch, you could create it (ensuring that all fields are of the correct data type, which is not guaranteed with a make-table query), and fill it from code.  Of course, clear it first with a SQL statement like this:

   strSQL = "DELETE * FROM tblOrderData_Temp"
   CurrentProject.Connection.Execute strSQL

OR

      CurrentDb.Execute strSQL, dbFailOnError

Open in new window

0
TechNinja2Author Commented:
Thank you Dale.  I reviewed the structure based on your questions and it got me thinking about the relationships I used.  After changing relationships, it pulled the records I needed.  (It took me some time to figure out so thx for your patience.)

Thx all!
0
Dale FyeOwner, Developing Solutions LLCCommented:
glad I could help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.