473,511 Members | 12,087 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 1366
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.querydefs("Query1")
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
3292
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...
3
8772
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...
1
2557
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
7150
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...
25
3815
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...
2
5726
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...
3
9207
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...
1
2477
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...
2
1679
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,...
0
7144
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...
0
7427
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...
1
7085
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...
0
5671
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,...
1
5069
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...
0
4741
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...
0
3227
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...
0
3214
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1577
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 ...

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.