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

Query Error Message

Tom
Using AccessXP in 2000 mode.

I have the following tables ---
TblLocation
LocationID
PropertyID
StateID
CountyID
CityID

TblState
StateID
State

A Type 1 relationship exists between StateID in both tables. I created a
query based on both tables that includes all the fields in TblLocation and
the State field in TblState. StateID is joined between the two tables in the
query. If I run the query, enter 1 for PropertyID and then try to close the
query, I get the following error message:
"The Microsoft Jet Database Engine can not find a record in the table
'TblState' with key matching field(s) 'StateID'.
When I click OK this message appears:
"You can not save the record at this time".
I get the same behaviour if I delete the relatinship between the tables and
just rely on the join in the query.
Why do I get this error message?

Thanks,

Tom
Nov 13 '05 #1
14 1686
Tom wrote:
Using AccessXP in 2000 mode.

I have the following tables ---
TblLocation
LocationID
PropertyID
StateID
CountyID
CityID

TblState
StateID
State

A Type 1 relationship exists between StateID in both tables. I created a
query based on both tables that includes all the fields in TblLocation and
the State field in TblState. StateID is joined between the two tables in the
query. If I run the query, enter 1 for PropertyID and then try to close the
query, I get the following error message:
"The Microsoft Jet Database Engine can not find a record in the table
'TblState' with key matching field(s) 'StateID'.
When I click OK this message appears:
"You can not save the record at this time".
I get the same behaviour if I delete the relatinship between the tables and
just rely on the join in the query.
Why do I get this error message?

Thanks,

Tom

Are you adding a new record? Have you entered a StateID? If no StateID
is entered, there is nothing to link to the state table.
Nov 13 '05 #2
Why do you need a StateID? I mean, if you're dealing with US states,
then they're already unique, and only 2 characters long. I'd just use
the State field and then use a combobox in my form.

SELECT State
FROM tblState
ORDER BY State

and be done with it. IMO, you're making this more complicated than it
needs to be.

Nov 13 '05 #3
Tom
Thanks for responding!

I thought null values are allowed in foreign key fields. Doesn't Access
apply the rule that the foreign key must match a record in the primary's
table's field or be null? StateID is a foreign key.

Tom
"Salad" <oi*@vinegar.com> wrote in message
news:uF**************@newsread3.news.pas.earthlink .net...
Tom wrote:
Using AccessXP in 2000 mode.

I have the following tables ---
TblLocation
LocationID
PropertyID
StateID
CountyID
CityID

TblState
StateID
State

A Type 1 relationship exists between StateID in both tables. I created a
query based on both tables that includes all the fields in TblLocation
and the State field in TblState. StateID is joined between the two tables
in the query. If I run the query, enter 1 for PropertyID and then try to
close the query, I get the following error message:
"The Microsoft Jet Database Engine can not find a record in the table
'TblState' with key matching field(s) 'StateID'.
When I click OK this message appears:
"You can not save the record at this time".
I get the same behaviour if I delete the relatinship between the tables
and just rely on the join in the query.
Why do I get this error message?

Thanks,

Tom

Are you adding a new record? Have you entered a StateID? If no StateID
is entered, there is nothing to link to the state table.

Nov 13 '05 #4
"Tom" <no***@email.com> wrote in message
news:9R****************@newsread1.news.atl.earthli nk.net...
Thanks for responding!

I thought null values are allowed in foreign key fields. Doesn't Access
apply the rule that the foreign key must match a record in the primary's
table's field or be null? StateID is a foreign key.

Tom


That is correct, but the field 'StateID' may have a default value (typically
zero for a long integer) so even though you leave it blank, zero is filled
in and this value does not appear in the related table. Check the design of
the table.
Nov 13 '05 #5
Tom
Thanks for your response, Justin!

I deleted the zero default value when I designed TblLocation so the default
value is blank. When I open the table and look at the new record line,
StateID is blank.

Tom
"Justin Hoffman" <j@b.com> wrote in message
news:dd**********@nwrdmz03.dmz.ncs.ea.ibs-infra.bt.com...
"Tom" <no***@email.com> wrote in message
news:9R****************@newsread1.news.atl.earthli nk.net...
Thanks for responding!

I thought null values are allowed in foreign key fields. Doesn't Access
apply the rule that the foreign key must match a record in the primary's
table's field or be null? StateID is a foreign key.

Tom


That is correct, but the field 'StateID' may have a default value
(typically zero for a long integer) so even though you leave it blank,
zero is filled in and this value does not appear in the related table.
Check the design of the table.

Nov 13 '05 #6
Tom
I changed StateID in TblLocation to StateInit and StateID in TblState to
StateInit. Made StateInit in TblState the primary key. I joined StateInit in
both tables in the query. Still get the same error message!
<pi********@hotmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Why do you need a StateID? I mean, if you're dealing with US states,
then they're already unique, and only 2 characters long. I'd just use
the State field and then use a combobox in my form.

SELECT State
FROM tblState
ORDER BY State

and be done with it. IMO, you're making this more complicated than it
needs to be.

Nov 13 '05 #7
"Tom" <no***@email.com> wrote in message
news:56****************@newsread1.news.atl.earthli nk.net...
Thanks for your response, Justin!

I deleted the zero default value when I designed TblLocation so the
default value is blank. When I open the table and look at the new record
line, StateID is blank.

Tom

That's good, isn't it? I'm sure removing the default value of zero is a
useful thing to do anyway - afterall, it serves no purpose - unless you have
a valid state with id=0.
Has that solved your problem or are you still stuck? I am not quite sure of
the purpose of your query. To add new records to TblLocation? To edit
them?

"Justin Hoffman" <j@b.com> wrote in message
news:dd**********@nwrdmz03.dmz.ncs.ea.ibs-infra.bt.com...
"Tom" <no***@email.com> wrote in message
news:9R****************@newsread1.news.atl.earthli nk.net...
Thanks for responding!

I thought null values are allowed in foreign key fields. Doesn't Access
apply the rule that the foreign key must match a record in the primary's
table's field or be null? StateID is a foreign key.

Tom


That is correct, but the field 'StateID' may have a default value
(typically zero for a long integer) so even though you leave it blank,
zero is filled in and this value does not appear in the related table.
Check the design of the table.


Nov 13 '05 #8
Tom
I'm still stuck! I was just pointing out that I had previously deleted the
zero when I first designed the table. The query will become the record
source for a form to add/edit records in TblLocation. But before I do that I
need to solve this problem because it will be there when I design the form.

Tom
"Justin Hoffman" <j@b.com> wrote in message
news:dd**********@nwrdmz03.dmz.ncs.ea.ibs-infra.bt.com...
"Tom" <no***@email.com> wrote in message
news:56****************@newsread1.news.atl.earthli nk.net...
Thanks for your response, Justin!

I deleted the zero default value when I designed TblLocation so the
default value is blank. When I open the table and look at the new record
line, StateID is blank.

Tom

That's good, isn't it? I'm sure removing the default value of zero is a
useful thing to do anyway - afterall, it serves no purpose - unless you
have a valid state with id=0.
Has that solved your problem or are you still stuck? I am not quite sure
of the purpose of your query. To add new records to TblLocation? To edit
them?

"Justin Hoffman" <j@b.com> wrote in message
news:dd**********@nwrdmz03.dmz.ncs.ea.ibs-infra.bt.com...
"Tom" <no***@email.com> wrote in message
news:9R****************@newsread1.news.atl.earthli nk.net...
Thanks for responding!

I thought null values are allowed in foreign key fields. Doesn't Access
apply the rule that the foreign key must match a record in the
primary's table's field or be null? StateID is a foreign key.

Tom

That is correct, but the field 'StateID' may have a default value
(typically zero for a long integer) so even though you leave it blank,
zero is filled in and this value does not appear in the related table.
Check the design of the table.



Nov 13 '05 #9
"Tom" wrote
I changed StateID in TblLocation to
StateInit and StateID in TblState to
StateInit. Made StateInit in TblState
the primary key. I joined StateInit in
both tables in the query. Still get the
same error message!


If by "Type 1" join, you mean an inner join, "only records with same
identification in both tables" -- there is no provision in that for "null",
there _must_ be records with the identical value in that field in both
tables for anything to display.

It's not fully clear to me what you are doing with your direct use of
queries, but I can suggest two things...

(1) try a join that only requires a record
in whichever table you are adding
records to (you'll have to use other
means to validate that the state initials
in the added record are valid)

(2) use a default value for the foreign key
field, for whichever state you'll use
most often

Larry Linson
Microsoft Access MVP
Nov 13 '05 #10
"Tom" <no***@email.com> wrote in message
news:Tm****************@newsread1.news.atl.earthli nk.net...
I'm still stuck! I was just pointing out that I had previously deleted the
zero when I first designed the table. The query will become the record
source for a form to add/edit records in TblLocation. But before I do that
I need to solve this problem because it will be there when I design the
form.

Tom


The normal way to do this would be to have the form based on TblLocation
only (or a query based on this single location). In order to show the state
rather than just the id, use a combobox to show the state name.
It is not the only one, but I would try this first.
Nov 13 '05 #11
Tom
Thanks for responding!

I thought null values are allowed in foreign key fields. Doesn't Access
apply the rule that the foreign key must match a record in the primary's
table's field or be null? StateID is a foreign key.

Tom

"Larry Linson" <bo*****@localhost.not> wrote in message
news:hv9Je.6296$Y2.4648@trnddc09...
"Tom" wrote
I changed StateID in TblLocation to
StateInit and StateID in TblState to
StateInit. Made StateInit in TblState
the primary key. I joined StateInit in
both tables in the query. Still get the
same error message!


If by "Type 1" join, you mean an inner join, "only records with same
identification in both tables" -- there is no provision in that for
"null", there _must_ be records with the identical value in that field in
both tables for anything to display.

It's not fully clear to me what you are doing with your direct use of
queries, but I can suggest two things...

(1) try a join that only requires a record
in whichever table you are adding
records to (you'll have to use other
means to validate that the state initials
in the added record are valid)

(2) use a default value for the foreign key
field, for whichever state you'll use
most often

Larry Linson
Microsoft Access MVP

Nov 13 '05 #12
I'm sorry, but I don't understand what you mean.

The "legality" of a Null value in a Foreign Key field means that the Record
can be written. Whether a Null is allowed, or not, in any field, is
determined by the Properties of that Field in the Table's definition. It is
not _necessarily_ so that every Field used as a Foreign Key can be Null. In
fact, unless you create a Relationship, Access will not _know_ that a Field
is to be used as a Foreign Key. FK is a matter of use, not of defining that
a field is an FK.

That "legality" has nothing to do with whether a Query using an Inner Join
(I like better the more descriptive term "Equi-Join") will return a Record.
They are two separate subjects.

Of course, the FK can be Null. And, you can get some results, even with a
Null FK, if you use one of the Outer Join types.

With an Inner Join there must be a matching key in the joined fields of both
tables _for a record to be returned_ by the Query.

And, I seem to recall that you implied by "Type 1" (not an official Access
term, but I assumed it applied to the first of the three possibilities shown
in the Join Type dialog) that you had use the Equ-Join.

Larry Linson
Microsoft Access MVP

"Tom" <no***@email.com> wrote in message
news:57****************@newsread2.news.atl.earthli nk.net...
Thanks for responding!

I thought null values are allowed in foreign key fields. Doesn't Access
apply the rule that the foreign key must match a record in the primary's
table's field or be null? StateID is a foreign key.

Tom

"Larry Linson" <bo*****@localhost.not> wrote in message
news:hv9Je.6296$Y2.4648@trnddc09...
"Tom" wrote
> I changed StateID in TblLocation to
> StateInit and StateID in TblState to
> StateInit. Made StateInit in TblState
> the primary key. I joined StateInit in
> both tables in the query. Still get the
> same error message!


If by "Type 1" join, you mean an inner join, "only records with same
identification in both tables" -- there is no provision in that for
"null", there _must_ be records with the identical value in that field in
both tables for anything to display.

It's not fully clear to me what you are doing with your direct use of
queries, but I can suggest two things...

(1) try a join that only requires a record
in whichever table you are adding
records to (you'll have to use other
means to validate that the state initials
in the added record are valid)

(2) use a default value for the foreign key
field, for whichever state you'll use
most often

Larry Linson
Microsoft Access MVP


Nov 13 '05 #13
Tom
I tried your suggestion in your first response and found that a right join
solved the problem.

Thanks,

Tom
"Larry Linson" <bo*****@localhost.not> wrote in message
news:mPfJe.3877$2j.3779@trnddc07...
I'm sorry, but I don't understand what you mean.

The "legality" of a Null value in a Foreign Key field means that the
Record can be written. Whether a Null is allowed, or not, in any field, is
determined by the Properties of that Field in the Table's definition. It
is not _necessarily_ so that every Field used as a Foreign Key can be
Null. In fact, unless you create a Relationship, Access will not _know_
that a Field is to be used as a Foreign Key. FK is a matter of use, not of
defining that a field is an FK.

That "legality" has nothing to do with whether a Query using an Inner Join
(I like better the more descriptive term "Equi-Join") will return a
Record. They are two separate subjects.

Of course, the FK can be Null. And, you can get some results, even with a
Null FK, if you use one of the Outer Join types.

With an Inner Join there must be a matching key in the joined fields of
both tables _for a record to be returned_ by the Query.

And, I seem to recall that you implied by "Type 1" (not an official Access
term, but I assumed it applied to the first of the three possibilities
shown in the Join Type dialog) that you had use the Equ-Join.

Larry Linson
Microsoft Access MVP

"Tom" <no***@email.com> wrote in message
news:57****************@newsread2.news.atl.earthli nk.net...
Thanks for responding!

I thought null values are allowed in foreign key fields. Doesn't Access
apply the rule that the foreign key must match a record in the primary's
table's field or be null? StateID is a foreign key.

Tom

"Larry Linson" <bo*****@localhost.not> wrote in message
news:hv9Je.6296$Y2.4648@trnddc09...
"Tom" wrote

> I changed StateID in TblLocation to
> StateInit and StateID in TblState to
> StateInit. Made StateInit in TblState
> the primary key. I joined StateInit in
> both tables in the query. Still get the
> same error message!

If by "Type 1" join, you mean an inner join, "only records with same
identification in both tables" -- there is no provision in that for
"null", there _must_ be records with the identical value in that field
in both tables for anything to display.

It's not fully clear to me what you are doing with your direct use of
queries, but I can suggest two things...

(1) try a join that only requires a record
in whichever table you are adding
records to (you'll have to use other
means to validate that the state initials
in the added record are valid)

(2) use a default value for the foreign key
field, for whichever state you'll use
most often

Larry Linson
Microsoft Access MVP



Nov 13 '05 #14
Tom wrote:
Thanks for responding!

I thought null values are allowed in foreign key fields. Doesn't Access
apply the rule that the foreign key must match a record in the primary's
table's field or be null? StateID is a foreign key.
You are using the wrong type of query. You are saying and attempting to
select all records from table1 that have a record in table2. You don't
add a state and then expect the two to be joined.

You are really making a lot of work on this for absolutely no purpose.

Someone mentioned using a combo box for entering the state. That seems
like a suitable solution since it's obvious you don't need a state to be
selected when a record is added.


Tom

"Larry Linson" <bo*****@localhost.not> wrote in message
news:hv9Je.6296$Y2.4648@trnddc09...
"Tom" wrote

I changed StateID in TblLocation to
StateInit and StateID in TblState to
StateInit. Made StateInit in TblState
the primary key. I joined StateInit in
both tables in the query. Still get the
same error message!


If by "Type 1" join, you mean an inner join, "only records with same
identification in both tables" -- there is no provision in that for
"null", there _must_ be records with the identical value in that field in
both tables for anything to display.

It's not fully clear to me what you are doing with your direct use of
queries, but I can suggest two things...

(1) try a join that only requires a record
in whichever table you are adding
records to (you'll have to use other
means to validate that the state initials
in the added record are valid)

(2) use a default value for the foreign key
field, for whichever state you'll use
most often

Larry Linson
Microsoft Access MVP


Nov 13 '05 #15

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

Similar topics

2
by: jaysonsch | last post by:
Hello! I am having some problems with a database query that I am trying to do. I am trying to develop a way to search a database for an entry and then edit the existing values. Upon submit, the...
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...
6
by: Martin Lacoste | last post by:
Ok, before I headbutt the computer... don't know why when I add criteria in a query, I get an 'invalid procedure call'. I also don't know why after searching the help in access, the various access...
4
by: Alan Lane | last post by:
Hello world: I'm including both code and examples of query output. I appologize if that makes this message longer than it should be. Anyway, I need to change the query below into a pivot table...
7
by: John Øllgård Jensen | last post by:
Hi Using MS Asccess 2000: In a query I'm trying to create a new field with following expression: FilmDate: Left(,4) The field "FilmNo" is another text field in the query. This is...
10
by: aaronrm | last post by:
I have a real simple cross-tab query that I am trying to sum on as the action but I am getting the "data type mismatch criteria expression" error. About three queries up the food chain from this...
2
by: salvadorvp | last post by:
Hi, I wonder If somebody has experience this or could point me in the right direction: I have the following script (commented out just to use the username): // Check username and password //...
6
by: Phil Stanton | last post by:
I am running a query that calls a function used to format addresses depending on the width of a control on a report that shows that address. The same query is used as the RecordSource of lots of...
16
by: ARC | last post by:
Hello all, So I'm knee deep in this import utility program, and am coming up with all sorts of "gotcha's!". 1st off. On a "Find Duplicates Query", does anyone have a good solution for...
4
by: franc sutherland | last post by:
Hello, I am using Access 2003. I am having trouble trapping the "can't append all the records in the append query" error message when appending data to a query from a table which is linked to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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: 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:
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?
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...

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.