473,626 Members | 3,240 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to edit a query and save in code?

51 New Member
I have a query named "Tuition Calculation" saved in the database.
In the code, the criteria of the query need to be added/modified and be saved for use of another auto-generate report.
Is DoCmd.OpenQuery the right one to use? it seems not work
Below is the what I tried, please advice.. thanks :-)

Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenQuery "Tuition Calculation", acViewDesign, acAdd
  2. [Queries]![Tuition Calculation].Criteria = "Year=" & Year & " and Semester=" & Semester
  3. DoCmd.Save acQuery
  4. DoCmd.Close acQuery, "Tuition Calculation"
  5.  
Aug 21 '07 #1
4 6937
Stwange
126 Recognized Expert New Member
I have a query named "Tuition Calculation" saved in the database.
In the code, the criteria of the query need to be added/modified and be saved for use of another auto-generate report.
Is DoCmd.OpenQuery the right one to use? it seems not work
Below is the what I tried, please advice.. thanks :-)

Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenQuery "Tuition Calculation", acViewDesign, acAdd
  2. [Queries]![Tuition Calculation].Criteria = "Year=" & Year & " and Semester=" & Semester
  3. DoCmd.Save acQuery
  4. DoCmd.Close acQuery, "Tuition Calculation"
  5.  
I'm not sure how to do exactly what you want (ie, pass parameters and then open a query), but I can show you how to pass parameters and then refer to the fields in a query - first write the query so it has criteria such as =[TheYear] for year and =[TheSemester] for semester (the names here don't have to mean anything), then:
Expand|Select|Wrap|Line Numbers
  1. Dim qdf As DAO.QueryDef
  2. Set qdf = DBEngine(0)(0).QueryDefs(queryName)
  3. Dim rs As DAO.Recordset
  4. qdf.Parameters(0) = Year
  5. qdf.Parameters(1) = Semester
  6. Set rs = qdf.OpenRecordset
  7. If Not rs.EOF Then
  8.     msgbox rs!<some_field> 'or whatever you want to do here
  9. end if
  10.  
Hope that helps, and good luck.
Aug 22 '07 #2
anniebai
51 New Member
I'm not sure how to do exactly what you want (ie, pass parameters and then open a query), but I can show you how to pass parameters and then refer to the fields in a query - first write the query so it has criteria such as =[TheYear] for year and =[TheSemester] for semester (the names here don't have to mean anything), then:
Expand|Select|Wrap|Line Numbers
  1. Dim qdf As DAO.QueryDef
  2. Set qdf = DBEngine(0)(0).QueryDefs(queryName)
  3. Dim rs As DAO.Recordset
  4. qdf.Parameters(0) = Year
  5. qdf.Parameters(1) = Semester
  6. Set rs = qdf.OpenRecordset
  7. If Not rs.EOF Then
  8.     msgbox rs!<some_field> 'or whatever you want to do here
  9. end if
  10.  
Hope that helps, and good luck.
Thank you, Stwange. But I need this query's design to be changed and be used for another report. Means after running the program, double-click the query, the data source (where criteria) of the query is changed.
Aug 22 '07 #3
JKing
1,206 Recognized Expert Top Contributor
Hi there.

If you have a report based of a query that has no where clause you can specific the criteria as you open the report. I think this is what you would like to do rather than change the query criteria, open the report, change the query and open another report.

Here's an example of using the Where Condition parameter of the openreport command.

Let's assume we have a report based off this simple query for a book catalogue.

Expand|Select|Wrap|Line Numbers
  1. SELECT bookID, bookName, bookAuthor, bookLength, bookCoverType
  2. FROM tblBook
  3.  
Expand|Select|Wrap|Line Numbers
  1.  Docmd.OpenReport "rptBookListing", acViewNormal,, "[bookAuthor] = 'Jared'",acWindowNormal 
  2.  
The report would only show books that have the author as Jared.

How I interpreted this correctly if not let me know and I'll try to work something else out.
Aug 22 '07 #4
anniebai
51 New Member
Hi there.

If you have a report based of a query that has no where clause you can specific the criteria as you open the report. I think this is what you would like to do rather than change the query criteria, open the report, change the query and open another report.

Here's an example of using the Where Condition parameter of the openreport command.

Let's assume we have a report based off this simple query for a book catalogue.

Expand|Select|Wrap|Line Numbers
  1. SELECT bookID, bookName, bookAuthor, bookLength, bookCoverType
  2. FROM tblBook
  3.  
Expand|Select|Wrap|Line Numbers
  1.  Docmd.OpenReport "rptBookListing", acViewNormal,, "[bookAuthor] = 'Jared'",acWindowNormal 
  2.  
The report would only show books that have the author as Jared.

How I interpreted this correctly if not let me know and I'll try to work something else out.
Oh, yes. this works for the purpose. Thank you !!
Aug 27 '07 #5

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

Similar topics

0
1276
by: dmiller23462 | last post by:
Hi guys... Haven't posted in some time.... I found a great example of what I need to do at the following link; http://www.asp101.com/samples/db_edit.asp The problem (and I've tried to modify the code unsuccessfully) is that I don't want to "Add a New Record" and I most definitely do not want to
3
2351
by: Heinz Willi Wiedow | last post by:
I'm developing smaller Websites with Asp.net and C#. For some Contents I want to develop a management system. At the moment a think about managing the contents via xml-files. For example the news section maybe has not more than 4 entries per page.
4
9403
by: Stephen | last post by:
Hello People, Using MS Access 2003 VBA I get the error 3020 Update or CancelUpdate without AddNew or Edit when I run through the following code. Can anyone help suggest anything to try? Thanks. On Error GoTo delete_failed Dim RS_DEL As DAO.Recordset
4
5377
by: Apple | last post by:
Can I edit an calculated field in my form if needed. Thank you in advance for your help. Sincerely Apple
4
3709
by: Glenn M | last post by:
I have a shared XML file on a server . i also have one xslt file that performs a simple transform on in to view the data. now i want to have another page that lets users modify the shared xml file via some editable controls such as text boxes , option boxes etc. how can i implment this , should i use another xslt file with <INPUT> controls . if so how can i save the result back using the asp.net
7
17538
by: Patrick Hatcher | last post by:
How can I view and edit a function in psql? I have been using PgAdmin to do this but wanted to try the command line TIA Patrick Hatcher
3
1985
by: Damon Grieves | last post by:
Hi I have a large table which I wanted to filter and then edit the selected record. I'm using a form with several pull down fields linked to lookup tables which correspond to fields in the large table. The user selects a number or category or All from the pull-down and this is used in a query, made up of the main table and the lookup tables with a suitable Iif statement to filter the query. So on the form there are several fields that...
1
2019
by: gurmet | last post by:
Hi All I have been looking around for help, and finally post this problem. I created a form to edit a record. Before i can click save button on the edit form i need to check if the data that have been edit exists in the table. But if i m calling the same record and updating the same record without changing anything it should allowed to save. Example: I m creating a table to save all types of courses (course_id, course_code,...
1
1482
by: beyrself | last post by:
Hi,all What i am trying to do now is to show the content of the dnsredir.ini file on the forms and able to edit it. The dnsredir.ini file file looks like this ;Configuration INI file for DNS Redirector v6.4.7 Logging=Normal
0
8269
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
8368
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6125
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5576
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4094
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4206
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2630
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1815
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1515
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.