473,382 Members | 1,147 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

How to create/delete queries with VBA like you can with tables?

Greetings all,

(Access 2003)

The bosses want me to take an old version of a database designed with a single-user-at-a-time mentality and update it to allow multiple, simultaneous users. The biggest trouble is that, based on its current design, simultaneous users could be potentially overwriting each other's data. I do have a work-around: I'll set up new temp-tables by capturing their in-house network usernames (JOHNSMITH) and treat it as a string variable that I can dump into the current code (with some modifications, of course). Essentially, I create/delete user-specific temp-tables by attaching the username to the end (i.e. old tbl_temp would now be tbl_temp_JOHNSMITH). So, when a user logs in, it autocreates their temp-tables, and all the things they do happen in their temp-tables (update master at the end).

But I hit a snag: one of the code-chunks references a saved query ("qry_bogus"); qry_bogus is just a dummy query whose querydef gets rewritten again and again. thus, it would be feasible for one user to click a button, setting the querydef to one line of SQL, then another person would come in, click their button and redefine it again, ruining the initial user's querydef--same problem I had before my temp-table solution.

So, can I create/delete a query strictly through VBA the way I create and delete tables? Is there a CreateQueryDef ability? Is there a "DROP QUERY"? That way, all I'd have to do is create/delete qry_bogus_JOHNSMITH the way I create/delete tbl_temp_JOHNSMITH. Each user would then be redefining the querydef of his own personal "qry_bogus".

Can this be done?
Feb 8 '11 #1

✓ answered by beacon

Hi tetsuo,

To answer your questions:

So, can I create/delete a query strictly through VBA the way I create and delete tables?
Yes

Is there a CreateQueryDef ability?
Yes

Just search for "VBA Create Query" online and you'll pull up a number of easy examples to work with.

Hope this helps and good luck,
beacon

3 2268
beacon
579 512MB
Hi tetsuo,

To answer your questions:

So, can I create/delete a query strictly through VBA the way I create and delete tables?
Yes

Is there a CreateQueryDef ability?
Yes

Just search for "VBA Create Query" online and you'll pull up a number of easy examples to work with.

Hope this helps and good luck,
beacon
Feb 8 '11 #2
Wow...you're right. I had it stuck in my head to look for "DROP QUERY" and couldn't find anything; should have looked for CreateQueryDef

Thanks!!
Feb 8 '11 #3
NeoPa
32,556 Expert Mod 16PB
You can use CurrentDb.CreateQueryDef(Name:="", SQLText:="Blah blah blah") to create a new query that is Temporary. That is, it is session level and is dropped automatically when the session terminates (You close the database or Access). Alternatively, you can use
Expand|Select|Wrap|Line Numbers
  1. Call DoCmd.CopyObject()
to make a copy of qry_Bogus and give it a name that reflects the user and the Date/Time it was created. If managed correctly this can be deleted when finished with, and you never again need worry about query updates affecting other users. This is designing for multiple-users, and makes the code re-entrant (which is necessary for multi-user projects).
Feb 9 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Chris | last post by:
Hi, sorry to post OT but i cant find the MySQL newsgroup, however i am hoping to pick up on some expert advice from php/mysql gurus here. I'm having some trouble performing a delete across two...
1
by: valexena | last post by:
How can I improve performance of queries on tables containing all words in the dictionary starting with the letter ‘S’? -- Posted via http://dbforums.com
6
by: Andreas Lauffer | last post by:
I changed from Access97 to AccessXP and I have immense performance problems. Details: - Access XP MDB with Jet 4.0 ( no ADP-Project ) - Linked Tables to SQL-Server 2000 over ODBC I used...
1
by: Craig Washington | last post by:
How in code can you use the Microsoft Access Queries with ADO in code? Anyone???
3
by: Stephen | last post by:
It is possible to relate queries to tables, right? It seems logical but when I try to match my queries to any of the tables or even to each other it gives me a blank relationship. What could I...
3
by: warren802 | last post by:
Hi, I'd just like to know how to catch the delete event for tables. In other words, how can I tell Access to do something first before deleting records in tables..I know that there is a delete...
3
by: rn5a | last post by:
I am trying to delete records from a MS-Access DB table using the following query: strSQL=DELETE FROM MyTable WHERE =CInt(Request.QueryString("delete")) con.Execute strSQL When I run the app...
16
by: ARC | last post by:
Hello all, So I'm knee deep in this import utility program, and am coming up with all sorts of "gotcha's!". 1st off. On a "Find Duplicates Query", does anyone have a good solution for...
3
by: musicloverlch | last post by:
I have been given a database with 2,944 tables in it. Each table has 35 rows and columns labeled Dur, 20, 21, 22, 23, 24, 25, 26 ..... 64, 65. They contain insurance rates by age and band. ...
1
atksamy
by: atksamy | last post by:
Hi, I am running a few delete queries which r getting executed without any error. But the data in tables are not getting deleted. It is as if the queries were not run. I ran them through...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.