473,671 Members | 2,550 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

replace query by pressing button on form

11 New Member
i'm trying to create a report that is based on selections from the user. i'm using a form which creates a query, by passing on the sql statement (from a hidden textbox) into the new query "query1". The report then uses this query as a source. however, the next time i want to carry out this routine the old query1 is not replaced by the new one. so the report displays the old information.

is it possible to replace the first query1 after pressing a button on the form? maybe deleting it first, before creating a new one?

thanks!
Apr 20 '07 #1
4 1374
travellinman
11 New Member
maybe the code that i'm using will clarify things some more (please tell me if the code is not entirely correct, i'm not an expert. i just scraped bits and pieces together):

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command5_Click()
  2. On Error GoTo ErrHandler
  3. Dim db As DAO.Database
  4. Dim qdf As DAO.QueryDef
  5. Dim strName As String
  6.    'first get a unique name for the querydef object
  7.    strName = Application.Run("acwzmain.wlib_stUniquedocname", "Query1", acQuery)
  8.       Set db = CurrentDb
  9.       Set qdf = db.CreateQueryDef(strName, Me.Text1)
  10.       qdf.Close
  11.  
  12. ExitHere:
  13.    On Error Resume Next
  14.    qdf.Close
  15.    Set qdf = Nothing
  16.    db.QueryDefs.Refresh
  17.    Set db = Nothing
  18.  
  19. ErrHandler:
  20.    Resume ExitHere
  21.  
  22.  
  23.  
  24.    On Error GoTo Err_Command5_Click
  25.  
  26.     Dim stDocName As String
  27.  
  28.     stDocName = "TestMAINreport"
  29.     DoCmd.OpenReport stDocName, acPreview
  30.  
  31. Exit_Command5_Click:
  32.     Exit Sub
  33.  
  34. Err_Command5_Click:
  35.     MsgBox Err.Description
  36.     Resume Exit_Command5_Click
  37.  
  38. End Sub
Apr 20 '07 #2
travellinman
11 New Member
never mind, found the code to do this:

Expand|Select|Wrap|Line Numbers
  1. DoCmd.DeleteObject acQuery, "Query1"
Apr 20 '07 #3
pks00
280 Recognized Expert Contributor
Personally I wouldnt bother creating and deleting new queries.

I would simply just set the sql each time
eg

dim qdf as dao.querydef

set qdf=currentdb.q uerydefs("Query 1")
qdf.SQL = Me.Text1


voila
Apr 20 '07 #4
travellinman
11 New Member
you're right, that's a lot better.

thanks!
Apr 20 '07 #5

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

Similar topics

5
3312
by: will eichert | last post by:
Greetings. I have a problem with a combo box incorrectly displaying blank items when returning to a form from a modal form. It's fine when the main form first comes up, but gets messed up when the main form is reactivated following opening and closing a modal form. Strangely, this was not a problem until I started using my Access 2000 db in Access 2003 (as an Access 2000 db). Details follow... I have an unbound combo box on my main form...
3
8783
by: jj | last post by:
Hi NG I have a form, where I can activate the search and replace dialogbox when pressing a button. My problem is that the dialogbox opens with the default that it should search for full match only, and I want it to open with default "a part of field". The VBA used is:
1
2576
by: carrionk | last post by:
Hi, I have created a Subform which SourceObject is a parameter query. This is the Query: Qry Name:80IsscomProduct SELECT * FROM Isscomp28 WHERE Like ;
2
7184
by: Cindy | last post by:
Hi all you smarties out there, I'm having a little conundrum with my asp.net page Scenario: I have a form (asp.net) with no code behind (as yet). I have placed a javascript function on a server side textbox control to do something - eg change the words on label - when the key pressed is the "enter" key. I can see the label change to what i expect ----- BUT .... then the
25
3850
by: artromanov | last post by:
Hello everyone. I am somewhat new to access and this forum. Hopefully it will be a great and helpful experience. My problem is this. I have a database (about 65,000 records). I get a run from another party every month in a text format (notepad) which I import into my database and make a comparison between the previous months and current months tables (some fields) by running a query. What I am trying to do is create a nice form that will ...
2
5731
by: Mark Roughton | last post by:
I have a form where the users need to view records for various criteria, one of which is a date field on which they may wish to view all related data for the selected date, for all dates upto and icluding the selected date or all records on or after the selected date The user selects either "=", >=" or "<=" from a combo box and then a date from another combobox. The combination of thse two choices is then set in an unbound textbox so...
3
9215
by: njgreen2001 | last post by:
I am attempting an access database which tracks blood components in our medical facility. When a component is issued to a patient there is a button to push which links to a report that runs a query. (The report is basically a paper that gets put in the medical record.) The user must enter the unique key for the component at a promt, which ensures the report generated will be for that component only. My question is if there is a way to...
1
2492
by: GlennMBella2 | last post by:
this is probably basic, however I ahve a form with number of buttons and upon pressing certain buttons as part of hte buttons press function, i would like to update a table (communications) with basic information. eg, pressing teh EMAIL button , after sending a outlook message i want funtion to update the table with current date.time pdatetimefield], also then a text field in table with "EMAILED"
2
1684
by: Vince Morgan | last post by:
Hi all, I have a POST form that also includes some anchors/links. If a user clicks a link, that link remains set so that pressing the submit button later not only sends the appropriate POST value, but also passes the previous link value. What I would dearly love to do is remove the query string after dealing with the passed value so that it isn't pased again when the submit button is susequently pressed. Would form.reset() be the right...
0
8401
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8926
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8824
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8603
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,...
0
7444
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5703
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
4227
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...
2
2060
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1815
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.