473,473 Members | 1,843 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how do I keep the query result when I switch to design view?

When I swtich to design view from data view, the query results are
lost, and I have to run again to get it. Is there an option in access
to keep the data when I switching views? I know I can copy them to
other place, such as excel, but I'd prefer to keep them in access.

thanks,

Wei

Sep 14 '06 #1
7 1671
What you're asking doesn't make sense. A query is a *definition* of a
resultset, and *not* the results themselves. If you want to save the
information somewhere,you'll have to write them to a table or
something. In short, no. once you close the query or return to design
view, the dataset is no longer available.

Sep 14 '06 #2
It does make sense, I wanna switch between design/sql and data view so
I can revise a query based on the previous data. and I only want the
updated resultset when I need to.

pi********@hotmail.com wrote:
What you're asking doesn't make sense. A query is a *definition* of a
resultset, and *not* the results themselves. If you want to save the
information somewhere,you'll have to write them to a table or
something. In short, no. once you close the query or return to design
view, the dataset is no longer available.
Sep 14 '06 #3

zwa...@gmail.com wrote:
It does make sense, I wanna switch between design/sql and data view so
I can revise a query based on the previous data. and I only want the
updated resultset when I need to.
You can't do that. A query is a DEFINITION ONLY. You'll have to put
the results somewhere that's static, like a table. Otherwise, you
can't do it. What the query returns when you run it is the resultset
that the query defines. There's an example of how to do what you want
in Access Developer's Handbook (Desktop). It's in one of the first few
chapters (the one on SQL). Other than that, I don't know how to do it.
Basically the way they solve it is to set the rowsource of the unbound
subform to the contents of the textbox at the top of the form. I think
you can download it from www.developershandbook.com

Don't think so... but it's on the ADH CD that comes with the book.
Only downside to ADH is that it is NOT a beginner book. Once you have
a pretty good handle on Access, it's a terrific book... but if you
don't have the basics down, it's a large paperweight.

Sep 14 '06 #4
zw****@gmail.com wrote:
It does make sense, I wanna switch between design/sql and data view so
I can revise a query based on the previous data. and I only want the
updated resultset when I need to.

pi********@hotmail.com wrote:
>What you're asking doesn't make sense. A query is a *definition* of a
resultset, and *not* the results themselves. If you want to save the
information somewhere,you'll have to write them to a table or
something. In short, no. once you close the query or return to design
view, the dataset is no longer available.
Makes sense to me as well, and perhaps you know as I do that some
environments save query results in new and separate windows from the
SQL, allowing you to toggle back and forth. Alas, Access does not work
this way.

--
Smartin
Sep 14 '06 #5
No, not natively, you would have to persist the resultset somewhere and then
switch to design view.

--

Terry Kreft
<zw****@gmail.comwrote in message
news:11**********************@e3g2000cwe.googlegro ups.com...
When I swtich to design view from data view, the query results are
lost, and I have to run again to get it. Is there an option in access
to keep the data when I switching views? I know I can copy them to
other place, such as excel, but I'd prefer to keep them in access.

thanks,

Wei

Sep 15 '06 #6

Terry Kreft wrote:
No, not natively, you would have to persist the resultset somewhere and then
switch to design view.
Terry,

do you have a quick example of doing that?

thanks,
Pieter

Sep 17 '06 #7
Knocked up this morning, so it's pretty rough.

e.g. It doesn't check that the queries are actually select queries and I'm
sure there are a bunch of bugs in it.
' PersistQueries: Allows you to persist all open queries to tables
' ClearTmpTables: Removes all temp tables created by PersistQueries
Option Compare Database
Option Explicit

Private Declare Function EnumChildWindows _
Lib "user32" (ByVal hWndParent As Long, _
ByVal lpEnumFunc As Long, _
ByVal lParam As Any) As Long
Private Declare Function GetWindowText _
Lib "user32" Alias "GetWindowTextA" _
(ByVal hwnd As Long, ByVal lpString As String, _
ByVal cch As Long) As Long
Private Declare Function GetTopWindow _
Lib "user32" ( _
ByVal hwnd As Long _
) As Long
Private Declare Function GetWindow _
Lib "user32" ( _
ByVal hwnd As Long, ByVal wCmd As Long _
) As Long
Private Declare Function GetClassName _
Lib "user32" Alias "GetClassNameA" ( _
ByVal hwnd As Long, ByVal lpClassName As String, _
ByVal nMaxCount As Long _
) As Long
' *************************************
'

Function PersistQueries() As String
Dim colQueries As Collection
Dim varValue As Variant

Set colQueries = EnumChild
For Each varValue In colQueries
Call PersistQry(Trim(Left(varValue(1), InStr(varValue(1), ":") - 1)))
Next
End Function

Function ClearTmpTables()
Dim intCount As Integer
Dim loTab As DAO.TableDef
Dim loProp As DAO.Property
Dim db As DAO.Database
Dim strTab As String

Set db = CurrentDb
For intCount = db.TableDefs.Count - 1 To 0 Step -1
Set loTab = db.TableDefs(intCount)

For Each loProp In loTab.Properties
If loProp.Name = "Temp" Then
If loProp.Value = True Then
On Error Resume Next
db.Execute "DROP TABLE " & loTab.Name
On Error GoTo 0
End If
End If
Next
Next
Set loTab = Nothing
Set db = Nothing
End Function

Private Sub PersistQry(strQDF As String)
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim loTab As DAO.TableDef
Dim strSQl As String
Dim strTab As String
Dim varSQL As Variant

Const SQL_INTO = " INTO "
Const SQL_FROM1 = vbCrLf & "FROM "
Const SQL_FROM2 = " FROM "

Set db = CurrentDb

Set qdf = db.QueryDefs(strQDF)

strSQl = qdf.SQL

qdf.Close
Set qdf = Nothing

strTab = "tmp_" & Hex(CLng(Time * 10 ^ 7)) & "_" & strQDF

If InStr(1, strSQl, SQL_FROM1, vbTextCompare) 0 Then
varSQL = Split(strSQl, SQL_FROM1)
strSQl = varSQL(0) & SQL_INTO & strTab & SQL_FROM1 & varSQL(1)
ElseIf InStr(1, strSQl, SQL_FROM2, vbTextCompare) 0 Then
varSQL = Split(strSQl, SQL_FROM2)
strSQl = varSQL(0) & SQL_INTO & strTab & SQL_FROM2 & varSQL(1)
End If

db.Execute strSQl

Set loTab = db.TableDefs(strTab)
With loTab
.Properties.Append .CreateProperty("Temp", dbBoolean, True, False)
End With
Set loTab = Nothing
Set db = Nothing

DoCmd.OpenTable strTab, acViewNormal, acReadOnly

End Sub
Function EnumChild() As Collection
Dim varItem As Variant
Dim colChildWins As Collection
Dim intCount As Integer

Const WIN_CLASS_QUERY = "OQry"

Set colChildWins = New Collection
Call EnumChildWindows(hWndAccessApp, AddressOf EnumWindowsProc,
colChildWins)
For intCount = colChildWins.Count To 1 Step -1
varItem = colChildWins(intCount)
If varItem(2) <WIN_CLASS_QUERY Then
colChildWins.Remove intCount
End If
Next
Set EnumChild = colChildWins
End Function

Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Collection) As
Long
Dim lpString As String, cch As Long
Dim lpClassName As String, nMaxCount As Long
Dim lngret As Long
Dim cWI As Variant

cch = 260
lpString = String(cch, 0)
lngret = GetWindowText(hwnd, lpString, cch)
If lngret 0 Then
lpString = Left(lpString, lngret)

nMaxCount = 260
lpClassName = Space(nMaxCount)
lngret = GetClassName(hwnd, lpClassName, nMaxCount)
lpClassName = Left(lpClassName, lngret)

cWI = Array(hwnd, lpString, lpClassName)
lParam.Add cWI
End If
EnumWindowsProc = True
End Function


--

Terry Kreft
<pi********@hotmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
>
Terry Kreft wrote:
No, not natively, you would have to persist the resultset somewhere and
then
switch to design view.
Terry,

do you have a quick example of doing that?

thanks,
Pieter

Sep 18 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Ryan | last post by:
I came across a situation that I've been unable to explain and was hoping somebody had an answer: I had written an update query which was taking about 8 seconds to run and considered it too...
8
by: Adam Louis | last post by:
I would like help resolving this problem. I'm a novice who's been hired to query a hospital database and extract useful information, available to me only in a dynamically generated, downloadable...
3
by: John young | last post by:
I have been looking for an answer to a problem and have found this group and hope you can assist . I have been re doing a data base I have made for a car club I am with and have been trying to...
4
by: Philippe | last post by:
Hello, I encounter a problem that I cannot solve myself... The problem is the following: I make a table: several records: the first field is always a number, the following field is always...
2
by: Michael Donahoe | last post by:
I have a database that I inherited that has query in it that has hidden fields when it is in design view. Datasheet view shows the fields and when I switch back to design view it appears as though...
6
by: jjturon | last post by:
Can anyone help me?? I am trying to pass a Select Query variable to a table using Dlookup and return the value to same select query but to another field. Ex. SalesManID ...
1
by: Regnab | last post by:
I often want to query the database with certain parameters in my query which I do not want included in the query result. The problem is when I want to group on 1, sum the 2nd (and group by) and...
3
by: mnjkahn via AccessMonster.com | last post by:
I'm running Access 2003, modifying a query that has over 45 fields. When I right click on the field name in Query Design View, and then click Build, Access crashes before the Build window...
1
by: david.triplett | last post by:
I am using MS Access 2007 and have an issue with writing queries against ODBC connected tables. After providing the appropriate ODBC connection string in the properties page, the Show Tables...
0
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,...
0
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,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
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
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
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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.