473,385 Members | 1,402 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,385 software developers and data experts.

Dao - Ado Modify Defined Query

My ERP software is dictating that I use ADO connections. I have been able to convert all my code except when I need to modify a querydef. In DAO it was like this:

Sub ReplaceQuery()

Dim dbs As Database, qdf As QueryDef
Set dbs = CurrentDb
dbs.QueryDefs.Refresh

For Each qdf In dbs.QueryDefs
If qdf.Name = "qryMyQuery" Then dbs.QueryDefs.Delete qdf.Name
Next qdf

strSQL = "SELECT * FROM MYDATA;"

Set qdf = dbs.CreateQueryDef("qryMyQuery", strSQL)

DoCmd.OpenQuery qdf.Name, acViewNormal, acReadOnly

Set dbs = Nothing

End Sub


I have simplified my sql statment for demo purposes only, but I must be able to modify a current query def in access 2000 using vba.

I have looked everywhere for weeks with no solution. If anyone can point me in the right direction, I would very much appreciate it.
Nov 13 '07 #1
2 3551
ADezii
8,834 Expert 8TB
My ERP software is dictating that I use ADO connections. I have been able to convert all my code except when I need to modify a querydef. In DAO it was like this:

Sub ReplaceQuery()

Dim dbs As Database, qdf As QueryDef
Set dbs = CurrentDb
dbs.QueryDefs.Refresh

For Each qdf In dbs.QueryDefs
If qdf.Name = "qryMyQuery" Then dbs.QueryDefs.Delete qdf.Name
Next qdf

strSQL = "SELECT * FROM MYDATA;"

Set qdf = dbs.CreateQueryDef("qryMyQuery", strSQL)

DoCmd.OpenQuery qdf.Name, acViewNormal, acReadOnly

Set dbs = Nothing

End Sub


I have simplified my sql statment for demo purposes only, but I must be able to modify a current query def in access 2000 using vba.

I have looked everywhere for weeks with no solution. If anyone can point me in the right direction, I would very much appreciate it.
You can avoid any References to DAO or ADO Object Libraries simply by creating a Base Query consisting of all possible Fields, then modifying the SQL Property of the Query then Opening it. I'm not sure if this will suit your purposes, but hopefully it was worth mentioning. A provided a simple code segment for you to view:
Expand|Select|Wrap|Line Numbers
  1. Dim strNewSQL As String
  2.  
  3. strNewSQL = "Select [FirstName], [LastName], [Title] From Employees;"
  4.  
  5. CurrentDb.QueryDefs("qryEmployees").SQL = strNewSQL
  6.  
  7. DoCmd.OpenQuery "qryEmployees", acViewNormal, acReadOnly
  8.  
Nov 14 '07 #2
You can avoid any References to DAO or ADO Object Libraries simply by creating a Base Query consisting of all possible Fields, then modifying the SQL Property of the Query then Opening it. I'm not sure if this will suit your purposes, but hopefully it was worth mentioning. A provided a simple code segment for you to view:
Expand|Select|Wrap|Line Numbers
  1. Dim strNewSQL As String
  2.  
  3. strNewSQL = "Select [FirstName], [LastName], [Title] From Employees;"
  4.  
  5. CurrentDb.QueryDefs("qryEmployees").SQL = strNewSQL
  6.  
  7. DoCmd.OpenQuery "qryEmployees", acViewNormal, acReadOnly
  8.  

It was very much worth mentioning. My sincere thanks to you. I overlooked the simple solution. Shame on me. Again, thank you.
Nov 15 '07 #3

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

Similar topics

0
by: Shailesh | last post by:
Hello, I want to set up some USER DEFINED METRICS in 10g. The restriction with USER DEFINED METRICS, is the query (or function ) monitoring that metrics should return only 1 value. I want to...
0
by: anzenews | last post by:
Hello! I have a weird problem... The application I use issues this SQL from time to time: alter table t modify id int(6) unique not null auto_increment; The problem is that this SQL adds a...
1
by: Glenn | last post by:
Searching through google groups, I have not found anyone able to modify the query string of a request. I was hoping to make the query string as short as possible so that a search with many...
2
by: David Emme | last post by:
Access 97 I have a number of SELECT statements which contain references to user-defined VBA functions. These typically work as expected, but occasionally, on one user's machine or another,...
3
by: KevLow | last post by:
Hi, Hope some kind soul can help me out here.. I'm trying to programmatically modify the column headings of a crosstab query such that it can be dynamic based on user specified period (Month...
28
by: Charles Sullivan | last post by:
I'm working on a program which has a "tree" of command line arguments, i.e., myprogram level1 ]] such that there can be more than one level2 argument for each level1 argument and more than one...
1
by: alps | last post by:
Hello friends , I am basically a delphi developer and am new to the VB.net technology.Can anyone out there give me a typical VB.net solution for a dataentry program for a table.Lets say...
4
by: Bob | last post by:
Hi all, I'm trying to import data, modify the data then insert it into a new table. The code below works fine for it but it takes a really long time for 15,000 odd records. Is there a way I...
0
by: frostbb | last post by:
Ok, stumped one more time, I'm trying to learn how to use a DataGridView in place of the old DataGrid control. QUESTION: How do I map the columns returned from a RunTime sql query to the columns...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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.