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

Run SQL For "many" table with relationship Established

I have an Access 97 database with 2 tables that have a one-many
relationship. I have a SQL statement in the "one" table which I want to
execute and insert 7 records into the "many" table, and I want them to be
linked to the "main" table.

Problem is, it won't let me run the SQL run as long as the one-many
relationship is established in the relationship window.

The SQL is:

Dim sSQL As String
For stDate = stBegDate To stEndDate
sSQL = "INSERT INTO tblScheduleActual_Test ( date1 ) SELECT #" & stDate & "#
AS Expr1;"
DoCmd.RunSQL sSQL
Next stDate

It loops through the dates of the week and inserts 7 records with successive
dates.

It works fine if I remove the relationship, but I figured the relationship
should be established in the relationship window.

Tips?

LRH
Nov 12 '05 #1
2 3399
TC
Not to answer your question, but, the following code is very unsafe:

"SELECT #" & stDate & "# ..."

If stDate is a string, it will be formatted accrding to your current PC
settings. But dates provided in #...# format must be provided in U.S.
(month/day/year) order, >regardless of your PC's settings<. So you should
really format stDate explicitly (using the Format$() function) into
month/day/year order in the SQL statement.

HTH,
TC
"Larry R Harrison Jr" <la*******@cox.net> wrote in message
news:ZjYsb.912$6G3.215@fed1read06...
I have an Access 97 database with 2 tables that have a one-many
relationship. I have a SQL statement in the "one" table which I want to
execute and insert 7 records into the "many" table, and I want them to be
linked to the "main" table.

Problem is, it won't let me run the SQL run as long as the one-many
relationship is established in the relationship window.

The SQL is:

Dim sSQL As String
For stDate = stBegDate To stEndDate
sSQL = "INSERT INTO tblScheduleActual_Test ( date1 ) SELECT #" & stDate & "# AS Expr1;"
DoCmd.RunSQL sSQL
Next stDate

It loops through the dates of the week and inserts 7 records with successive dates.

It works fine if I remove the relationship, but I figured the relationship
should be established in the relationship window.

Tips?

LRH

Nov 12 '05 #2
"Larry R Harrison Jr" <la*******@cox.net> wrote in message news:<ZjYsb.912$6G3.215@fed1read06>...
I have an Access 97 database with 2 tables that have a one-many
relationship. I have a SQL statement in the "one" table which I want to
execute and insert 7 records into the "many" table, and I want them to be
linked to the "main" table.

Problem is, it won't let me run the SQL run as long as the one-many
relationship is established in the relationship window.

The SQL is:

Dim sSQL As String
For stDate = stBegDate To stEndDate
sSQL = "INSERT INTO tblScheduleActual_Test ( date1 ) SELECT #" & stDate & "#
AS Expr1;"
DoCmd.RunSQL sSQL
Next stDate

It loops through the dates of the week and inserts 7 records with successive
dates.

It works fine if I remove the relationship, but I figured the relationship
should be established in the relationship window.

Tips?

LRH

You must be violating referential integrity. Otherwise it would work
fine. You need to include the primary key from the 1-side table...
Sub InsertValues(dtStart as date, dtFinish as date)

dim db as dao.database
dim rs as dao.recordset
dim dtDate As Date

set db = dbengine(0)(0)
set rs=db.opentable("MyDates",dbOpenTable)
for dtDate - dtStart to dtFinish
rs.Addnew
rs.Fields("MyDate")=dtDate
rs.Update
next dtDate

rs.close
set rs=nothing
set db=nothing

or use db.Execute... but that and RunSQL are SLOW!!! (try looping like
1000 times... you'll cry it's so slow).
Nov 12 '05 #3

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

Similar topics

3
by: Bill MacLean | last post by:
-- Example Schema posted at end of message: --- For reporting purposes, I need to build a single comma delimited string of values from the "many" table of a database. The easiest way to see...
3
by: Paul Janssen | last post by:
Hello! Can anyone help me out with the following situation: (a) a single query with 550 id's in the IN-clause resulting into 800+ seconds; (b) 550 queries with a single id in the IN-clause...
6
by: Paul T. Rong | last post by:
Dear all, Here is my problem: There is a table "products" in my access database, since some of the products are out of date and stopped manufacture, I would like to delete those PRODUCTS from...
3
bartonc
by: bartonc | last post by:
Most of the lines in this fuction deal with null data and default data: def FillFromDB(self): gradeSense = None slopeSense = None gradeOffset = None ...
0
by: Ofelia | last post by:
Hi, I'm new to this forum and to Perl language but I would like to ask for your help. I'm working in Linux and the files I need to process are in the format “file.gz”. I created a script which...
4
bugboy
by: bugboy | last post by:
I'm inserting a new word into table 'w' and a definition into table 'c' which are linked in table 's' which is the relation table for the many to many relationship between 'w' and 'c'. I've been...
1
by: Cirene | last post by:
I have a gridview that displays a listing of cars for sale. It's based on a "Cars" table. (The "Cars" table has a 1 to many relationship to "CarPictures" table.) On each gridview row (ie for...
5
by: lsllcm | last post by:
Hi All, I have one question about many "or" operation make system choose incorrect index There is one table TT ( C1 VARCHAR(15) NOT NULL, C2 VARCHAR(15) NOT NULL, C3 VARCHAR(15) NOT NULL,...
1
by: per9000 | last post by:
We have a big application written without thought of supporting multiple languages with lots of strings in a default "english". Now the client wants to support any language (with a latin alphabet)...
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?
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
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
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.