473,386 Members | 1,820 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.

Odd recordset behavior

Hello.

Before going further, I should mention that I have found a
workaround for this problem. However, I thought it was
sufficiently interesting to try to find out what is causing it.

I have a form which launches when the application is started.
The form is not initially databound. . .the user must first select
a value from a combobox on the form. When the user selects
a value, an appropriate recordset is created and cloned to the
form's Recordsource property. The ControlSource properties
for the form's controls are then set, and we're good to go.

On odd thing that is happening however is that the recordset
fields all return NULL on the very first record fetch, with the
exception of the primary key. Like so:

cObj.customer_id = me!customer_id 'Primary key--no error
cObj.last_name = me!last_name 'INVALID USE OF NULL
cObj.first_name = me!first_name 'INVALID USE OF NULL

All subsequent fetches during the current application session
do not exhibit this problem. If the user selects a different entry
from the combobox (which changes the form's recordsource)
the problem does not reoccur then either.

The workaround was to fully-qualify the non-PKID field
references:

cObj.customer_id = me!customer_id 'Primary key--no error
cObj.last_name = me.Recordset!last_name 'no error
cObj.first_name = me.Recordset!first_name 'no error

If anyone here knows why this is happening, I would like to
know.

Thanks
-Mark
Feb 19 '06 #1
6 1770
DAO or ADO?

i have no clue, either way, just wanted to replicate the error to play
with it a while.

Feb 19 '06 #2
"Jamey Shuemaker" <ca*********@yahoo.com> wrote:
DAO or ADO?


I am using DAO and Access 2000.

A few more details:

The form has a Recordsource assigned in design mode,
which is deleted in the form_load() procedure. If I leave
Recordsource blank in design mode, I get compiler errors.

The various controls have their ControlSource values set
in design mode as well. The form_load() procedure saves
these into a collection and then erases them. (I could also
leave them blank in design mode and just assign them when
the user makes a selection from the combobox.)

When the user makes a selection from the combo box,
a DAO recordset is created with the appropriate query
reference. This recordset is cloned to the form's
Recordset property, and the reference is deleted.
Finally, the procedure walks the collection of
ControlSource properties and assigns them to the
appropriate controls. The form is now data-aware.

This may be a totally bizarre way to go about this, but it
is what I was able to come up with. I would welcome any
simpler alternatives that I may have missed (I prefer not
to use a "startup switchboard" form to make the
Recordsource selection.)

-Mark

Feb 19 '06 #3
On Sun, 19 Feb 2006 14:22:49 -0800, "Mark" <no****@thanksanyway.org> wrote:
"Jamey Shuemaker" <ca*********@yahoo.com> wrote:
DAO or ADO?

I am using DAO and Access 2000.

A few more details:

The form has a Recordsource assigned in design mode,
which is deleted in the form_load() procedure. If I leave
Recordsource blank in design mode, I get compiler errors.

Your code would need to be in the Form_Open event instead of Form_Load.
The load event fires after the open event, and at this point data has been
loaded and the fields bound to the recordsource. If you delete the recordsource
in the load event you are breaking the link between the bound controls and their
data. Hence the errors.

If you do delete the recordsource in the load event, you would first need to
delete the control's ControlSource before you deleted the recordsource.
The various controls have their ControlSource values set
in design mode as well. The form_load() procedure saves
these into a collection and then erases them. (I could also
leave them blank in design mode and just assign them when
the user makes a selection from the combobox.)

When the user makes a selection from the combo box,
a DAO recordset is created with the appropriate query
reference. This recordset is cloned to the form's
Recordset property, and the reference is deleted.
Finally, the procedure walks the collection of
ControlSource properties and assigns them to the
appropriate controls. The form is now data-aware.

This may be a totally bizarre way to go about this, but it
is what I was able to come up with. I would welcome any
simpler alternatives that I may have missed (I prefer not
to use a "startup switchboard" form to make the
Recordsource selection.)

-Mark


It sounds to me like you are making alot of extra work for yourself.
I would create a separate form for each possible selection from the combo, each
bound to it's own query.
Make each of the forms the same size, and add a subform control to your main
form of equivalent size. On the AfterUpdate of the combo just change the
SourceObject of the subform contol to the name of the appropriate form to
display.
Wayne Gillespie
Gosford NSW Australia
Feb 19 '06 #4
"Wayne Gillespie" <be*****@NOhotmailSPAM.com.au> wrote:
On Sun, 19 Feb 2006 14:22:49 -0800, "Mark" <no****@thanksanyway.org>
wrote:
The form has a Recordsource assigned in design mode,
which is deleted in the form_load() procedure. If I leave
Recordsource blank in design mode, I get compiler errors.
Your code would need to be in the Form_Open event instead of Form_Load.
The load event fires after the open event, and at this point data has been
loaded and the fields bound to the recordsource. If you delete the
recordsource
in the load event you are breaking the link between the bound controls and
their
data. Hence the errors.

If you do delete the recordsource in the load event, you would first need
to
delete the control's ControlSource before you deleted the recordsource.


I am getting the same result even if I delete the recordsource in
form_open(). The form loads, and the controls all display #NAME?.
In order to prevent this I need to erase all the ControlSource properties,
whether I delete the recordsource in form_open() or in form_load().

Incidentally, the compiler error was a different issue. That had to do with
a procedure that was referencing fields in the form's recordset.
Even though the procedure would only run in a context in which the form
actually _had_ a recorset, the compiler did not know that. So I had to
assign a recordsource in design mode to please the compiler.
It sounds to me like you are making alot of extra work for yourself.


Possibly. If there is a way I can delete the form's recordsource without
the bound controls displaying an error, then I will use it. Regarding your
multiple-forms proposal, I really prefer to have additional code instead
of multiple copies of the same form. It's just a preference I guess. I can
see how your approach would work as well.

Thanks
-Mark
Feb 20 '06 #5
"Mark" <no****@thanksanyway.org> wrote:
The workaround was to fully-qualify the non-PKID field
references:

cObj.customer_id = me!customer_id 'Primary key--no error
cObj.last_name = me.Recordset!last_name 'no error
cObj.first_name = me.Recordset!first_name 'no error


Well darnit, in following up on Wayne's recommendations I
discovered that my workaround is NOT working. When I
include the Recordset qualifier in the object reference, I actually
get the data from the PREVIOUS record! The wrong data is displayed.

So my new workaround is to check for ERR_INVALID_USE_OF_NULL on
the non-PKID field reference. If ERR_INVALID_USE_OF_NULL is
encountered, I create an entirely new DAO recordset and retrieve
the desired non-PKID value for the current PKID.

UGLY!

But at least it works, and it only occurs on the very first
record fetch of the application session.

-Mark

Feb 20 '06 #6
Mark wrote:
"Wayne Gillespie" <be*****@NOhotmailSPAM.com.au> wrote:
On Sun, 19 Feb 2006 14:22:49 -0800, "Mark" <no****@thanksanyway.org>
wrote:

The form has a Recordsource assigned in design mode,
which is deleted in the form_load() procedure. If I leave
Recordsource blank in design mode, I get compiler errors.


Your code would need to be in the Form_Open event instead of Form_Load.
The load event fires after the open event, and at this point data has been
loaded and the fields bound to the recordsource. If you delete the
recordsource
in the load event you are breaking the link between the bound controls and
their
data. Hence the errors.

If you do delete the recordsource in the load event, you would first need
to
delete the control's ControlSource before you deleted the recordsource.

I am getting the same result even if I delete the recordsource in
form_open(). The form loads, and the controls all display #NAME?.
In order to prevent this I need to erase all the ControlSource properties,
whether I delete the recordsource in form_open() or in form_load().

Incidentally, the compiler error was a different issue. That had to do with
a procedure that was referencing fields in the form's recordset.
Even though the procedure would only run in a context in which the form
actually _had_ a recorset, the compiler did not know that. So I had to
assign a recordsource in design mode to please the compiler.

It sounds to me like you are making alot of extra work for yourself.

Possibly. If there is a way I can delete the form's recordsource without
the bound controls displaying an error, then I will use it. Regarding your
multiple-forms proposal, I really prefer to have additional code instead
of multiple copies of the same form. It's just a preference I guess. I can
see how your approach would work as well.

Thanks
-Mark


I have/had a situation where, when the main form, unbound, opens
initially it doesn't recognize NZ() function calls, etc. Once another
form has to be opened and then it works OK. I had to write some special
SQL statements for the form and use others throughout, even tho they all
do the same.
Feb 20 '06 #7

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

Similar topics

2
by: Roland Hall | last post by:
I have two(2) issues. I'm experiencing a little difficulty and having to resort to a work around. I already found one bug, although stated the bug was only in ODBC, which I'm not using. It...
14
by: deko | last post by:
For some reason this does not seem to be working... Am I missing something basic? Dim rst As DAO.Recordset Dim db As DAO.Database Set db = CurrentDb Set rst = db.OpenRecordset("qryEmailS") '...
4
by: MNC | last post by:
I'm using Access2002, and can't seem to get an updateable recordset going :-( What am I doing wrong, here's the code. The form's controls are not locked, the recordset type is Dynaset (changing...
6
by: lenny | last post by:
Hi, I've been trying to use a Sub or Function in VBA to connect to a database, make a query and return the recordset that results from the query. The connection to the database and the query...
0
by: sneal | last post by:
A little background: We have an Access 2002 based user interface to our SQL Server 2000 database. The interface is a tabbed form with two of the tabs containing a subform. Data is pulled from the...
9
by: Lauren Quantrell | last post by:
Does changing the Recordset Type property for a form in an Access ADP have any effect on possible record locking? I have a continuous form that is bound to a table but I don't want it editable,...
5
by: mail | last post by:
Urgent help needed! I moved an application from ASP+ACCESS to ASP+MS SQLSERVER and I have the following problem: If the join on two tables results on duplicate colum names (which appear in...
2
by: Tom Clavel | last post by:
Scratching my head. I am using the filter property on a combo box .AfterUpdate event to get to a single client record. This is causing a some strange behavior: As I enter a subform, I get a no...
2
by: wallconor | last post by:
Hi, I am having a problem using Dreamweaver CS3 standard recordset paging behavior. It doesn’t seem to work when I pass parameter values from a FORM on my search page, to the recordset on my...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...

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.