PC Review


Reply
Thread Tools Rate Thread

Auto add to table

 
 
=?Utf-8?B?Z2JfUzQ5?=
Guest
Posts: n/a
 
      18th May 2006
I am a complete novice to access, so apologies for the simplicity of the
question.
I have 2 tables.
Table one contains a list of names etc.
Table 2 contains many columns but the second column contains numbers 1-31,
entries per name (table 1)
Is there a way that when I add a new entry to table 1, it will automatically
create a additional 31 records (numbered 1-31) in table 2?
i hope this makes sense
 
Reply With Quote
 
 
 
 
=?Utf-8?B?QmFycnkgR2lsYmVydA==?=
Guest
Posts: n/a
 
      18th May 2006
What you're asking for might be a little advanced. First of all, you can't
really automate anything if you directly enter records into a table. You'll
need to create a form based on your table and perform inserts there. The form
will allow you to automate things like table inserts.

To do the insert, I would recommend looking into Append queries. The hard
part for you will be to increment the 1-31 thingy, but I would take it one
step at a time.

Barry

"gb_S49" wrote:

> I am a complete novice to access, so apologies for the simplicity of the
> question.
> I have 2 tables.
> Table one contains a list of names etc.
> Table 2 contains many columns but the second column contains numbers 1-31,
> entries per name (table 1)
> Is there a way that when I add a new entry to table 1, it will automatically
> create a additional 31 records (numbered 1-31) in table 2?
> i hope this makes sense

 
Reply With Quote
 
Pieter Wijnen
Guest
Posts: n/a
 
      18th May 2006


In the AfterInsert Event in the form U can put
(select Properties /Event / After Update Event / "builder" / Event
Procedure)


'--------------------------------------------------

Sub Form_AfterInsert()
Dim Db AS DAO.Database
Dim QDef AS DAO.QueryDef
Dim i AS Long
Dim SQL AS String

Set Db = Access.CurrentDb ' Pointer to DB
SQL="PARAMETERS pNAME TEXT, pVal Long;" & VBA.VbCrlF & _
"INSERT INTO TABLE2 ([NAME],Field2) VALUES (pName,pVal)"
Set Qdef = Db.CreateQueryDef(VBA.vbNullString,SQL) ' Creates a temporary
Query to insert records

Qdef.Parameters("pName").Value = Me("Name").Value ' Retrieve the Value of
the Forms Control "Name" & Assign to Query Parm
For i = 1 To 31
Qdef.Parameters("pVal").Value = i
Qdef.Execute DAO.DbSeeChanges 'Insert one row of data
Next ' Loop 1..31
Set Qdef = Nothing
Set Db = Nothing ' Cleanup Pointers
End Sub

'-------------------------------------

PS Change Field & Control Names to whatever U Use
HTH

Pieter


"gb_S49" <(E-Mail Removed)> wrote in message
news:82FC4748-3131-450F-8F1E-(E-Mail Removed)...
>I am a complete novice to access, so apologies for the simplicity of the
> question.
> I have 2 tables.
> Table one contains a list of names etc.
> Table 2 contains many columns but the second column contains numbers 1-31,
> entries per name (table 1)
> Is there a way that when I add a new entry to table 1, it will
> automatically
> create a additional 31 records (numbered 1-31) in table 2?
> i hope this makes sense



 
Reply With Quote
 
Joseph Meehan
Guest
Posts: n/a
 
      18th May 2006
gb_S49 wrote:
> I am a complete novice to access, so apologies for the simplicity of
> the question.
> I have 2 tables.
> Table one contains a list of names etc.
> Table 2 contains many columns but the second column contains numbers
> 1-31, entries per name (table 1)
> Is there a way that when I add a new entry to table 1, it will
> automatically create a additional 31 records (numbered 1-31) in table
> 2?
> i hope this makes sense


It would appear that properly have one table to the individual and then
as second related table for some sort of event(s) that take place on a daily
bases. Right now you appear to be recording the data on a monthly bases.
Maybe it might be better to record those events as the happen and record the
actual date they occur. That way you will not have blank records created,
and you will be able to query for a month, a week or any time period you
might need or want. No need to delete older data and you can have that for
reference.

Also I get suspicious when someone has "many columns" That may be a
candidate for additional normalization. Also remember that databases don't
have columns, they have fields that may be displayed in columns. Thinking
in terms of columns and not fields tends to make one not notice that the
data needs to be normalized. :-)

Good Luck

--
Joseph Meehan

Dia duit


 
Reply With Quote
 
=?Utf-8?B?Z2JfUzQ5?=
Guest
Posts: n/a
 
      19th May 2006
Pieter,
Thank you

"Pieter Wijnen" wrote:

>
>
> In the AfterInsert Event in the form U can put
> (select Properties /Event / After Update Event / "builder" / Event
> Procedure)
>
>
> '--------------------------------------------------
>
> Sub Form_AfterInsert()
> Dim Db AS DAO.Database
> Dim QDef AS DAO.QueryDef
> Dim i AS Long
> Dim SQL AS String
>
> Set Db = Access.CurrentDb ' Pointer to DB
> SQL="PARAMETERS pNAME TEXT, pVal Long;" & VBA.VbCrlF & _
> "INSERT INTO TABLE2 ([NAME],Field2) VALUES (pName,pVal)"
> Set Qdef = Db.CreateQueryDef(VBA.vbNullString,SQL) ' Creates a temporary
> Query to insert records
>
> Qdef.Parameters("pName").Value = Me("Name").Value ' Retrieve the Value of
> the Forms Control "Name" & Assign to Query Parm
> For i = 1 To 31
> Qdef.Parameters("pVal").Value = i
> Qdef.Execute DAO.DbSeeChanges 'Insert one row of data
> Next ' Loop 1..31
> Set Qdef = Nothing
> Set Db = Nothing ' Cleanup Pointers
> End Sub
>
> '-------------------------------------
>
> PS Change Field & Control Names to whatever U Use
> HTH
>
> Pieter
>
>
> "gb_S49" <(E-Mail Removed)> wrote in message
> news:82FC4748-3131-450F-8F1E-(E-Mail Removed)...
> >I am a complete novice to access, so apologies for the simplicity of the
> > question.
> > I have 2 tables.
> > Table one contains a list of names etc.
> > Table 2 contains many columns but the second column contains numbers 1-31,
> > entries per name (table 1)
> > Is there a way that when I add a new entry to table 1, it will
> > automatically
> > create a additional 31 records (numbered 1-31) in table 2?
> > i hope this makes sense

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to us macro for designing a statistic table (i.e soccer score table) auto update after i enter the game result felixt996@gmail.com Microsoft Excel Programming 3 7th Jul 2007 06:26 PM
Write data to Access table with INSERT when table has auto number =?Utf-8?B?SG9raWV2YW5kYWw=?= Microsoft Excel Programming 1 20th Dec 2006 01:19 AM
Retrieve data from flatfile to table plus auto update table and re =?Utf-8?B?SmF5X3JvbWFv?= Microsoft Access Getting Started 5 5th Jan 2006 11:51 AM
Auto Dealership: Trade table and Vehice table neccessary? =?Utf-8?B?RXZlcmdyZWVu?= Microsoft Access Database Table Design 1 18th Feb 2005 12:26 PM
Re: Pivot Table Auto Refresh and Auto Flow to columns Frank Kabel Microsoft Excel Misc 0 27th Jul 2004 07:29 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:51 PM.