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

Persistent Object Reference

I need to create an object (a recordset) that will not go out of scope
outside the sub that creates it. I've tried placing the Dim statement
in the General area and in another mod as Global; neither works.

(I'm creating the recordset with dynamic SQL.)

Any ideas on this?
Nov 13 '05 #1
7 2134
On 15 Nov 2004 17:40:53 -0800, we*****@verizon.net (Weaver) wrote:

Global objects are declared with the Global keyword:
(in a standard module)
Global g_rsSomething As Recordset

-Tom.

I need to create an object (a recordset) that will not go out of scope
outside the sub that creates it. I've tried placing the Dim statement
in the General area and in another mod as Global; neither works.

(I'm creating the recordset with dynamic SQL.)

Any ideas on this?


Nov 13 '05 #2
On Mon, 15 Nov 2004 20:20:46 -0700, Tom van Stiphout <no*************@cox.net>
wrote:
On 15 Nov 2004 17:40:53 -0800, we*****@verizon.net (Weaver) wrote:

Global objects are declared with the Global keyword:
(in a standard module)
Global g_rsSomething As Recordset

-Tom.

I need to create an object (a recordset) that will not go out of scope
outside the sub that creates it. I've tried placing the Dim statement
in the General area and in another mod as Global; neither works.

(I'm creating the recordset with dynamic SQL.)

Any ideas on this?


Also, unless this is a disconnected ADO recordset, you'll have to keep a
reference to the Database (DAO) or Connection (DAO) as well, since the
recordset needs its database/connection to function.
Nov 13 '05 #3
This is what I've done:

In a separate module kept for globals and widely used functions:

Global gblLMDrsPrev As Recordset
Global gblLMDdb As Database

In the form's module:

SQL = "SELECT * FROM tblForecast WHERE uidConfidence = " +
Format(uidNow)
Set gblLMDrsPrev = gblLMDdb.OpenRecordset(SQL, dbOpenSnapshot)

gblLMDrsPrev is lost to me after the form is moved to another record
in it's own recordsource.

(BTW, In the 'SQL =' line of code above, the 'Format' function call is
actually on the same line as the rest.)

Thanks again for your help.

Steve Jorgensen <no****@nospam.nospam> wrote in message news:<fh********************************@4ax.com>. ..
On Mon, 15 Nov 2004 20:20:46 -0700, Tom van Stiphout <no*************@cox.net>
wrote:
On 15 Nov 2004 17:40:53 -0800, we*****@verizon.net (Weaver) wrote:

Global objects are declared with the Global keyword:
(in a standard module)
Global g_rsSomething As Recordset

-Tom.

I need to create an object (a recordset) that will not go out of scope
outside the sub that creates it. I've tried placing the Dim statement
in the General area and in another mod as Global; neither works.

(I'm creating the recordset with dynamic SQL.)

Any ideas on this?


Also, unless this is a disconnected ADO recordset, you'll have to keep a
reference to the Database (DAO) or Connection (DAO) as well, since the
recordset needs its database/connection to function.

Nov 13 '05 #4
This is actually a followup to my previous post, which hasn't appeared
yet.

I was, out of habit, closing the database object. Sorry if I waisted
anyone's time on this one.

Thanks for your help.
Steve Jorgensen <no****@nospam.nospam> wrote in message news:<fh********************************@4ax.com>. ..
On Mon, 15 Nov 2004 20:20:46 -0700, Tom van Stiphout <no*************@cox.net>
wrote:
On 15 Nov 2004 17:40:53 -0800, we*****@verizon.net (Weaver) wrote:

Global objects are declared with the Global keyword:
(in a standard module)
Global g_rsSomething As Recordset

-Tom.

I need to create an object (a recordset) that will not go out of scope
outside the sub that creates it. I've tried placing the Dim statement
in the General area and in another mod as Global; neither works.

(I'm creating the recordset with dynamic SQL.)

Any ideas on this?


Also, unless this is a disconnected ADO recordset, you'll have to keep a
reference to the Database (DAO) or Connection (DAO) as well, since the
recordset needs its database/connection to function.

Nov 13 '05 #5
You reminded me of something persistent I've never solved. I have a
little form to filter reports by dates. Each report has (in my
tblReports) the name of the date field by which one is likely to
filter it, thus, the code below.

However, if I call it with, say, rptListChecksToPrint, the silly
OpenArgs seems to hold onto that report name. When I later call it
with rptChecks, I get the previous report, unless I close the
database. I tried tracing OpenArgs, and, sure enough, it's the
previous value.

Any ideas?

Private Sub Preview_Click()
Dim stCriteria As String
If IsNull([Beginning Date]) And IsNull([End Date]) Then
MsgBox ("Running report for all dates")
stCriteria = ""
ElseIf IsNull([Beginning Date]) Or IsNull([End Date]) Then
MsgBox "You must either enter both dates or no date at all!"
DoCmd.GoToControl "Beginning Date"
ElseIf [Beginning Date] > [End Date] Then
MsgBox "Ending date must be greater than Beginning date."
DoCmd.GoToControl "Beginning Date"
Else
stCriteria = "[" & tlookup("DateFieldName", "tblReports",
"Reportname='" & Me.OpenArgs & "'")
stCriteria = stCriteria & " ] between #" & [Beginning Date]
& "# and #" & [End Date] & "#"
End If

DoCmd.OpenReport Me.OpenArgs, A_PREVIEW, , stCriteria
Me.Visible = False
End Sub
Nov 13 '05 #6
I use OpenArgs to pass parameters to reports all the time, and have never seen
the problem you describe. Are you shure its not the calling code that has
somehow held on to the value in a variable that gets passed to OpenArgs?

I have seen bugs in my own code with similar symptoms to what you describe,
and it usually means I've passed the wrong piece of data to OpenArgs, but it
just happened to have the correct value for the first case I tested.

On 16 Nov 2004 20:11:54 -0800, pe***********@aol.com (Penguin) wrote:
You reminded me of something persistent I've never solved. I have a
little form to filter reports by dates. Each report has (in my
tblReports) the name of the date field by which one is likely to
filter it, thus, the code below.

However, if I call it with, say, rptListChecksToPrint, the silly
OpenArgs seems to hold onto that report name. When I later call it
with rptChecks, I get the previous report, unless I close the
database. I tried tracing OpenArgs, and, sure enough, it's the
previous value.

Any ideas?

Private Sub Preview_Click()
Dim stCriteria As String
If IsNull([Beginning Date]) And IsNull([End Date]) Then
MsgBox ("Running report for all dates")
stCriteria = ""
ElseIf IsNull([Beginning Date]) Or IsNull([End Date]) Then
MsgBox "You must either enter both dates or no date at all!"
DoCmd.GoToControl "Beginning Date"
ElseIf [Beginning Date] > [End Date] Then
MsgBox "Ending date must be greater than Beginning date."
DoCmd.GoToControl "Beginning Date"
Else
stCriteria = "[" & tlookup("DateFieldName", "tblReports",
"Reportname='" & Me.OpenArgs & "'")
stCriteria = stCriteria & " ] between #" & [Beginning Date]
& "# and #" & [End Date] & "#"
End If

DoCmd.OpenReport Me.OpenArgs, A_PREVIEW, , stCriteria
Me.Visible = False
End Sub


Nov 13 '05 #7
Well, I knew I must be making a mistake somewhere, because there
couldn't possibly be a bug in Access, could there (VBG)?

So, I decided to examine all the code again very carefully, as you
suggested. The main resource being my 12-year-old son looking over my
shoulder. And, lo and behold, he said, "Look at:
DoCmd.OpenReport Me.OpenArgs, A_PREVIEW, , stCriteria
Me.Visible = False
End Sub

You are hiding your form, Mom, but you're never closing it, so of
course, it doesn't get new OpenArgs when you think you're re-opening
it, because you're only making the old one visible!"

"Wow, how'd you figure that out?" I asked him.

"Oh, you once showed me something similar," he replied modestly.

So thanks for pointing in this direction, Steve.

Steve Jorgensen <no****@nospam.nospam> wrote in message news:<n8********************************@4ax.com>. .. I use OpenArgs to pass parameters to reports all the time, and have never seen
the problem you describe. Are you shure its not the calling code that has
somehow held on to the value in a variable that gets passed to OpenArgs?

I have seen bugs in my own code with similar symptoms to what you describe,
and it usually means I've passed the wrong piece of data to OpenArgs, but it
just happened to have the correct value for the first case I tested.

On 16 Nov 2004 20:11:54 -0800, pe***********@aol.com (Penguin) wrote:
You reminded me of something persistent I've never solved. I have a
little form to filter reports by dates. Each report has (in my
tblReports) the name of the date field by which one is likely to
filter it, thus, the code below.

However, if I call it with, say, rptListChecksToPrint, the silly
OpenArgs seems to hold onto that report name. When I later call it
with rptChecks, I get the previous report, unless I close the
database. I tried tracing OpenArgs, and, sure enough, it's the
previous value.

Any ideas?

Private Sub Preview_Click()
Dim stCriteria As String
If IsNull([Beginning Date]) And IsNull([End Date]) Then
MsgBox ("Running report for all dates")
stCriteria = ""
ElseIf IsNull([Beginning Date]) Or IsNull([End Date]) Then
MsgBox "You must either enter both dates or no date at all!"
DoCmd.GoToControl "Beginning Date"
ElseIf [Beginning Date] > [End Date] Then
MsgBox "Ending date must be greater than Beginning date."
DoCmd.GoToControl "Beginning Date"
Else
stCriteria = "[" & tlookup("DateFieldName", "tblReports",
"Reportname='" & Me.OpenArgs & "'")
stCriteria = stCriteria & " ] between #" & [Beginning Date]
& "# and #" & [End Date] & "#"
End If

DoCmd.OpenReport Me.OpenArgs, A_PREVIEW, , stCriteria
Me.Visible = False
End Sub

Nov 13 '05 #8

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

Similar topics

16
by: Paul Rubin | last post by:
I've had this recurring half-baked desire for long enough that I thought I'd post about it, even though I don't have any concrete proposals and the whole idea is fraught with hazards. Basically...
0
by: obhayes | last post by:
Hi All, Im using classic ASP (3.0) and I have a web farm with 2 webservers (webserver A and webserver B, both windows server 2003). I do not want to store any client specific information on the...
1
by: brad | last post by:
Hi, Im using classic ASP (3.0) and I have a web farm with 2 webservers (webserver A and webserver B, both windows server 2003). I do not want to store any client specific information on the...
4
by: M?rio Amado Alves | last post by:
Will you help an outsider trying to trace the current state of persistent object technology? "I expect that there will be persistent object stores with STL-conforming interfaces fitting into the...
12
by: marcadonis | last post by:
Hi! Does anybody know of a way that I can keep a reference to an object that I can then reuse? I tried various approaches using navigator, but these all fail in an iframe due to premission...
1
by: Eric Lindsay | last post by:
I am trying to understand the differences between and uses of persistent, default and alternate styles. I have read http://www.w3.org/TR/REC-html40/present/styles.html section 14.3.2 on...
7
by: Tony M. | last post by:
I'm trying to execute an append query. I have a case that works, and one that returns an object not set error. THIS WORKS: Private Sub cmdArchiveRecs_Click() BeginTrans CurrentDb.Execute...
8
by: castironpi | last post by:
I'd like a persistent deque, such that the instance operations all commit atomicly to file system.
9
by: mel | last post by:
Hi all, I need a persistent TCP connection with my web server over page reloads. This means that, even if the user goes to a different page (in my domain), I want to keep a TCP connection...
4
by: castironpi | last post by:
Some time ago, I was asking about the feasibility of a persistent deque, a double-ended queue. It runs into the typical space allocation problems. If you're storing a pickle, you have to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
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...
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...
0
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
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...

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.