A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Append New Records in Subform



 
 
Thread Tools Display Modes
  #1  
Old April 30th, 2008, 02:50 AM posted to microsoft.public.access.forms
ridgerunner
external usenet poster
 
Posts: 118
Default Append New Records in Subform

Is it possible to append new records in a subform, as it opens, to an
underlying table using only certain fields from an existing table?
  #2  
Old April 30th, 2008, 03:53 AM posted to microsoft.public.access.forms
strive4peace
external usenet poster
 
Posts: 1,670
Default Append New Records in Subform

hi ridgerunner (what is your name?)

yes, of course smile

can you describe a bit more about why you want to do this and where the
data would come from?

Warm Regards,
Crystal

Access Basics
8-part free tutorial that covers essentials in Access
http://www.accessmvp.com/Strive4Peace/Index.htm

*
(: have an awesome day
*



ridgerunner wrote:
Is it possible to append new records in a subform, as it opens, to an
underlying table using only certain fields from an existing table?

  #3  
Old April 30th, 2008, 01:46 PM posted to microsoft.public.access.forms
ridgerunner
external usenet poster
 
Posts: 118
Default Append New Records in Subform

I would rather not put my name in a public place if that is OK.

The form would open and autopopulate two fields, same data every time, and
then the data entry person would add the data required for the other fields
in the underlying table. This would speed things up tremendously.
The data would come from two fields in a table located in the same database.

"strive4peace" wrote:

hi ridgerunner (what is your name?)

yes, of course smile

can you describe a bit more about why you want to do this and where the
data would come from?

Warm Regards,
Crystal

Access Basics
8-part free tutorial that covers essentials in Access
http://www.accessmvp.com/Strive4Peace/Index.htm

*
(: have an awesome day
*



ridgerunner wrote:
Is it possible to append new records in a subform, as it opens, to an
underlying table using only certain fields from an existing table?


  #4  
Old April 30th, 2008, 07:19 PM posted to microsoft.public.access.forms
ridgerunner
external usenet poster
 
Posts: 118
Default Append New Records in Subform

There will be 34 records created everytime the form is used. One of the
fields will contain one of five categories and the other field will contain
one of 34 questions. Since the fields reside in a master reference table in
the database I thought it would be easier to append the fields from that
table into new records underlying the subform. From there it would be a
simple matter to add data to the remaining fields.

"strive4peace" wrote:

Hi ridgerunner

yes, it is fine ... but I like to ask anyway so hope you don't mind

If the data is the same every time, how about using the DefaultValue
property of the respective controls? Also, if the user will not
normally change it, then make the TabStop property = No. the user can
always click in to make a change

If the data changes depending on conditions, will those conditions be
the same for that edit session (ie: are they dependent on date?) or will
they change for different records?


Warm Regards,
Crystal

Access Basics
8-part free tutorial that covers essentials in Access
http://www.accessmvp.com/Strive4Peace/Index.htm

*
(: have an awesome day
*



ridgerunner wrote:
I would rather not put my name in a public place if that is OK.

The form would open and autopopulate two fields, same data every time, and
then the data entry person would add the data required for the other fields
in the underlying table. This would speed things up tremendously.
The data would come from two fields in a table located in the same database.

"strive4peace" wrote:

hi ridgerunner (what is your name?)

yes, of course smile

can you describe a bit more about why you want to do this and where the
data would come from?

Warm Regards,
Crystal

Access Basics
8-part free tutorial that covers essentials in Access
http://www.accessmvp.com/Strive4Peace/Index.htm

*
(: have an awesome day
*



ridgerunner wrote:
Is it possible to append new records in a subform, as it opens, to an
underlying table using only certain fields from an existing table?


  #5  
Old April 30th, 2008, 07:27 PM posted to microsoft.public.access.forms
strive4peace
external usenet poster
 
Posts: 1,670
Default Append New Records in Subform

Hi ridgerunner

yes, it is fine ... but I like to ask anyway so hope you don't mind

If the data is the same every time, how about using the DefaultValue
property of the respective controls? Also, if the user will not
normally change it, then make the TabStop property = No. the user can
always click in to make a change

If the data changes depending on conditions, will those conditions be
the same for that edit session (ie: are they dependent on date?) or will
they change for different records?


Warm Regards,
Crystal

Access Basics
8-part free tutorial that covers essentials in Access
http://www.accessmvp.com/Strive4Peace/Index.htm

*
(: have an awesome day
*



ridgerunner wrote:
I would rather not put my name in a public place if that is OK.

The form would open and autopopulate two fields, same data every time, and
then the data entry person would add the data required for the other fields
in the underlying table. This would speed things up tremendously.
The data would come from two fields in a table located in the same database.

"strive4peace" wrote:

hi ridgerunner (what is your name?)

yes, of course smile

can you describe a bit more about why you want to do this and where the
data would come from?

Warm Regards,
Crystal

Access Basics
8-part free tutorial that covers essentials in Access
http://www.accessmvp.com/Strive4Peace/Index.htm

*
(: have an awesome day
*



ridgerunner wrote:
Is it possible to append new records in a subform, as it opens, to an
underlying table using only certain fields from an existing table?

  #6  
Old April 30th, 2008, 09:29 PM posted to microsoft.public.access.forms
ridgerunner
external usenet poster
 
Posts: 118
Default Append New Records in Subform

I created an append query that will work when run from only the subform. I
do not know how to get this to work when the subform is embedded in the main
form. I tried a button to run the query on the main form but nothing
happened. I cannot see the button if I place it on the subform, since the
subform must be viewed in data sheet view. If I need to call the query from
an event I do not know how to do that and would really appreciate help. The
main form creates a record with an ID that is copied into the subform for
linking purposes.

"ridgerunner" wrote:

There will be 34 records created everytime the form is used. One of the
fields will contain one of five categories and the other field will contain
one of 34 questions. Since the fields reside in a master reference table in
the database I thought it would be easier to append the fields from that
table into new records underlying the subform. From there it would be a
simple matter to add data to the remaining fields.

"strive4peace" wrote:

Hi ridgerunner

yes, it is fine ... but I like to ask anyway so hope you don't mind

If the data is the same every time, how about using the DefaultValue
property of the respective controls? Also, if the user will not
normally change it, then make the TabStop property = No. the user can
always click in to make a change

If the data changes depending on conditions, will those conditions be
the same for that edit session (ie: are they dependent on date?) or will
they change for different records?


Warm Regards,
Crystal

Access Basics
8-part free tutorial that covers essentials in Access
http://www.accessmvp.com/Strive4Peace/Index.htm

*
(: have an awesome day
*



ridgerunner wrote:
I would rather not put my name in a public place if that is OK.

The form would open and autopopulate two fields, same data every time, and
then the data entry person would add the data required for the other fields
in the underlying table. This would speed things up tremendously.
The data would come from two fields in a table located in the same database.

"strive4peace" wrote:

hi ridgerunner (what is your name?)

yes, of course smile

can you describe a bit more about why you want to do this and where the
data would come from?

Warm Regards,
Crystal

Access Basics
8-part free tutorial that covers essentials in Access
http://www.accessmvp.com/Strive4Peace/Index.htm

*
(: have an awesome day
*



ridgerunner wrote:
Is it possible to append new records in a subform, as it opens, to an
underlying table using only certain fields from an existing table?


  #7  
Old April 30th, 2008, 09:37 PM posted to microsoft.public.access.forms
strive4peace
external usenet poster
 
Posts: 1,670
Default Append New Records in Subform

creating question records for a survey
~~~

Hi ridgerunner,

thanks for the additional information

since you did not specify fieldnames, I will use what I consider good,
generic names and you will have to change them

I am assuming your database includes tables with a structure similar to
the following:

Participants
- ParticID, autonumber, PK
- Lastname, text
- firstname, text

Questions
- QuestionID, autonumber, PK
- Question, text

Surveys
- SurveyID, autonumber, PK
- ParticID, long, FK to Participants
- SurvDate, date/time

SurveyAnswers
- SurvAnsID, autonumber
- SurveyID, long, fk to Surveys
- QuestionID, long, FK to Questions
- Answer

PK is Primary Key
FK is Foreign Key

this is a simplified example. It does not take into account that you
may have multiple types of surveys with different sets of questions

In SurveyAnswers, make a multi-field unique index on the combination of
SurveyID
QuestionID

this will protect you in case questions are created twice so you do not
get duplicates.

(multi-field unique indexes are covered in Access Basics, link in my siggy)

I am assuming that you have a main form/subform situation where the main
form is based on Surveys and the subform based on SurveyAnswers, which
is the table you wish to automatically fill records in

create a command button on the main form to create the questions

'~~~~~~~~~~~~~~~~~
'save record if changes have been made
if me.dirty then me.dirty = false

'if we are on a new record, give user a message
if me.newrecord then
msgbox "You are not on a current record" _
,, "Cannot create questions"
exit sub
end if

if isnull(me.ParticID) then
msgbox "You must fill out who you are" _
,, "Cannot create questions"
me.ParticID.setFocus
exit sub
end if

dim strSQL as string

strSQL = "INSERT INTO SurveyAnswers (SurveyID, QuestionID) " _
& " SELECT " & me.surveyID _
& ", QuestionID " _
& " FROM Questions;"

'remove this line once everything works ok
debug.print strSQL

currentdb.execute strSQL

'make the new records show up on the subform
me.subform_controlname.requery
'~~~~~~~~~~~~~~~~~

substitute the Name property of your subform control for subform_controlname

'~~~~~~~~~ Compile ~~~~~~~~~

Whenever you change code or references, your should always compile
before executing.

from the menu in a VBE (module) window: Debug, Compile

fix any errors on the yellow highlighted lines

keep compiling until nothing happens (this is good!)

~~~~~~~~~~~~~~~~
** debug.print ***

debug.print strSQL

-- this prints a copy of the SQL statement to the debug window (CTRL-G)

After you execute your code, open the Debug window
CTRL-G to Goto the debuG window -- look at the SQL statement

If the SQL statement has an error

1. Make a new query (design view)

2. choose View, SQL from the menu
(or SQL from the toolbar, first icon)

3. cut the SQL statement from the debug window
(select, CTRL-X)

4. paste into the SQL window of the Query
(CTRL-V)

5. run ! from the SQL window
-- Access will tell you where the problem is in the SQL



Warm Regards,
Crystal

Access Basics
8-part free tutorial that covers essentials in Access
http://www.accessmvp.com/Strive4Peace/Index.htm

*
(: have an awesome day
*



ridgerunner wrote:
There will be 34 records created everytime the form is used. One of the
fields will contain one of five categories and the other field will contain
one of 34 questions. Since the fields reside in a master reference table in
the database I thought it would be easier to append the fields from that
table into new records underlying the subform. From there it would be a
simple matter to add data to the remaining fields.

"strive4peace" wrote:

Hi ridgerunner

yes, it is fine ... but I like to ask anyway so hope you don't mind

If the data is the same every time, how about using the DefaultValue
property of the respective controls? Also, if the user will not
normally change it, then make the TabStop property = No. the user can
always click in to make a change

If the data changes depending on conditions, will those conditions be
the same for that edit session (ie: are they dependent on date?) or will
they change for different records?


Warm Regards,
Crystal

Access Basics
8-part free tutorial that covers essentials in Access
http://www.accessmvp.com/Strive4Peace/Index.htm

*
(: have an awesome day
*



ridgerunner wrote:
I would rather not put my name in a public place if that is OK.

The form would open and autopopulate two fields, same data every time, and
then the data entry person would add the data required for the other fields
in the underlying table. This would speed things up tremendously.
The data would come from two fields in a table located in the same database.

"strive4peace" wrote:

hi ridgerunner (what is your name?)

yes, of course smile

can you describe a bit more about why you want to do this and where the
data would come from?

Warm Regards,
Crystal

Access Basics
8-part free tutorial that covers essentials in Access
http://www.accessmvp.com/Strive4Peace/Index.htm

*
(: have an awesome day
*



ridgerunner wrote:
Is it possible to append new records in a subform, as it opens, to an
underlying table using only certain fields from an existing table?

  #8  
Old May 1st, 2008, 01:34 AM posted to microsoft.public.access.forms
ridgerunner
external usenet poster
 
Posts: 118
Default Append New Records in Subform

Thanks, but this isn't a survey; it is an inspection form that is completed
exactly the same way every time an inspection is completed. Does the "INSERT
INTO" add only one record at a time?

"strive4peace" wrote:

creating question records for a survey
~~~

Hi ridgerunner,

thanks for the additional information

since you did not specify fieldnames, I will use what I consider good,
generic names and you will have to change them

I am assuming your database includes tables with a structure similar to
the following:

Participants
- ParticID, autonumber, PK
- Lastname, text
- firstname, text

Questions
- QuestionID, autonumber, PK
- Question, text

Surveys
- SurveyID, autonumber, PK
- ParticID, long, FK to Participants
- SurvDate, date/time

SurveyAnswers
- SurvAnsID, autonumber
- SurveyID, long, fk to Surveys
- QuestionID, long, FK to Questions
- Answer

PK is Primary Key
FK is Foreign Key

this is a simplified example. It does not take into account that you
may have multiple types of surveys with different sets of questions

In SurveyAnswers, make a multi-field unique index on the combination of
SurveyID
QuestionID

this will protect you in case questions are created twice so you do not
get duplicates.

(multi-field unique indexes are covered in Access Basics, link in my siggy)

I am assuming that you have a main form/subform situation where the main
form is based on Surveys and the subform based on SurveyAnswers, which
is the table you wish to automatically fill records in

create a command button on the main form to create the questions

'~~~~~~~~~~~~~~~~~
'save record if changes have been made
if me.dirty then me.dirty = false

'if we are on a new record, give user a message
if me.newrecord then
msgbox "You are not on a current record" _
,, "Cannot create questions"
exit sub
end if

if isnull(me.ParticID) then
msgbox "You must fill out who you are" _
,, "Cannot create questions"
me.ParticID.setFocus
exit sub
end if

dim strSQL as string

strSQL = "INSERT INTO SurveyAnswers (SurveyID, QuestionID) " _
& " SELECT " & me.surveyID _
& ", QuestionID " _
& " FROM Questions;"

'remove this line once everything works ok
debug.print strSQL

currentdb.execute strSQL

'make the new records show up on the subform
me.subform_controlname.requery
'~~~~~~~~~~~~~~~~~

substitute the Name property of your subform control for subform_controlname

'~~~~~~~~~ Compile ~~~~~~~~~

Whenever you change code or references, your should always compile
before executing.

from the menu in a VBE (module) window: Debug, Compile

fix any errors on the yellow highlighted lines

keep compiling until nothing happens (this is good!)

~~~~~~~~~~~~~~~~
** debug.print ***

debug.print strSQL

-- this prints a copy of the SQL statement to the debug window (CTRL-G)

After you execute your code, open the Debug window
CTRL-G to Goto the debuG window -- look at the SQL statement

If the SQL statement has an error

1. Make a new query (design view)

2. choose View, SQL from the menu
(or SQL from the toolbar, first icon)

3. cut the SQL statement from the debug window
(select, CTRL-X)

4. paste into the SQL window of the Query
(CTRL-V)

5. run ! from the SQL window
-- Access will tell you where the problem is in the SQL



Warm Regards,
Crystal

Access Basics
8-part free tutorial that covers essentials in Access
http://www.accessmvp.com/Strive4Peace/Index.htm

*
(: have an awesome day
*



ridgerunner wrote:
There will be 34 records created everytime the form is used. One of the
fields will contain one of five categories and the other field will contain
one of 34 questions. Since the fields reside in a master reference table in
the database I thought it would be easier to append the fields from that
table into new records underlying the subform. From there it would be a
simple matter to add data to the remaining fields.

"strive4peace" wrote:

Hi ridgerunner

yes, it is fine ... but I like to ask anyway so hope you don't mind

If the data is the same every time, how about using the DefaultValue
property of the respective controls? Also, if the user will not
normally change it, then make the TabStop property = No. the user can
always click in to make a change

If the data changes depending on conditions, will those conditions be
the same for that edit session (ie: are they dependent on date?) or will
they change for different records?


Warm Regards,
Crystal

Access Basics
8-part free tutorial that covers essentials in Access
http://www.accessmvp.com/Strive4Peace/Index.htm

*
(: have an awesome day
*



ridgerunner wrote:
I would rather not put my name in a public place if that is OK.

The form would open and autopopulate two fields, same data every time, and
then the data entry person would add the data required for the other fields
in the underlying table. This would speed things up tremendously.
The data would come from two fields in a table located in the same database.

"strive4peace" wrote:

hi ridgerunner (what is your name?)

yes, of course smile

can you describe a bit more about why you want to do this and where the
data would come from?

Warm Regards,
Crystal

Access Basics
8-part free tutorial that covers essentials in Access
http://www.accessmvp.com/Strive4Peace/Index.htm

*
(: have an awesome day
*



ridgerunner wrote:
Is it possible to append new records in a subform, as it opens, to an
underlying table using only certain fields from an existing table?


  #9  
Old May 1st, 2008, 03:14 AM posted to microsoft.public.access.forms
strive4peace
external usenet poster
 
Posts: 1,670
Default Append New Records in Subform

Hi ridgerunner,

"this isn't a survey"

the analogy is the same. I made guesses since you did not specify much.

"Does the "INSERT INTO" add only one record at a time?"

no, it will add all the records from the questions table since there is
no criteria to limit it. I was assuming you would want to fill
everything out...


Warm Regards,
Crystal

Access Basics
8-part free tutorial that covers essentials in Access
http://www.accessmvp.com/Strive4Peace/Index.htm

*
(: have an awesome day
*



ridgerunner wrote:
Thanks, but this isn't a survey; it is an inspection form that is completed
exactly the same way every time an inspection is completed. Does the "INSERT
INTO" add only one record at a time?

"strive4peace" wrote:

creating question records for a survey
~~~

Hi ridgerunner,

thanks for the additional information

since you did not specify fieldnames, I will use what I consider good,
generic names and you will have to change them

I am assuming your database includes tables with a structure similar to
the following:

Participants
- ParticID, autonumber, PK
- Lastname, text
- firstname, text

Questions
- QuestionID, autonumber, PK
- Question, text

Surveys
- SurveyID, autonumber, PK
- ParticID, long, FK to Participants
- SurvDate, date/time

SurveyAnswers
- SurvAnsID, autonumber
- SurveyID, long, fk to Surveys
- QuestionID, long, FK to Questions
- Answer

PK is Primary Key
FK is Foreign Key

this is a simplified example. It does not take into account that you
may have multiple types of surveys with different sets of questions

In SurveyAnswers, make a multi-field unique index on the combination of
SurveyID
QuestionID

this will protect you in case questions are created twice so you do not
get duplicates.

(multi-field unique indexes are covered in Access Basics, link in my siggy)

I am assuming that you have a main form/subform situation where the main
form is based on Surveys and the subform based on SurveyAnswers, which
is the table you wish to automatically fill records in

create a command button on the main form to create the questions

'~~~~~~~~~~~~~~~~~
'save record if changes have been made
if me.dirty then me.dirty = false

'if we are on a new record, give user a message
if me.newrecord then
msgbox "You are not on a current record" _
,, "Cannot create questions"
exit sub
end if

if isnull(me.ParticID) then
msgbox "You must fill out who you are" _
,, "Cannot create questions"
me.ParticID.setFocus
exit sub
end if

dim strSQL as string

strSQL = "INSERT INTO SurveyAnswers (SurveyID, QuestionID) " _
& " SELECT " & me.surveyID _
& ", QuestionID " _
& " FROM Questions;"

'remove this line once everything works ok
debug.print strSQL

currentdb.execute strSQL

'make the new records show up on the subform
me.subform_controlname.requery
'~~~~~~~~~~~~~~~~~

substitute the Name property of your subform control for subform_controlname

'~~~~~~~~~ Compile ~~~~~~~~~

Whenever you change code or references, your should always compile
before executing.

from the menu in a VBE (module) window: Debug, Compile

fix any errors on the yellow highlighted lines

keep compiling until nothing happens (this is good!)

~~~~~~~~~~~~~~~~
** debug.print ***

debug.print strSQL

-- this prints a copy of the SQL statement to the debug window (CTRL-G)

After you execute your code, open the Debug window
CTRL-G to Goto the debuG window -- look at the SQL statement

If the SQL statement has an error

1. Make a new query (design view)

2. choose View, SQL from the menu
(or SQL from the toolbar, first icon)

3. cut the SQL statement from the debug window
(select, CTRL-X)

4. paste into the SQL window of the Query
(CTRL-V)

5. run ! from the SQL window
-- Access will tell you where the problem is in the SQL



Warm Regards,
Crystal

Access Basics
8-part free tutorial that covers essentials in Access
http://www.accessmvp.com/Strive4Peace/Index.htm

*
(: have an awesome day
*



ridgerunner wrote:
There will be 34 records created everytime the form is used. One of the
fields will contain one of five categories and the other field will contain
one of 34 questions. Since the fields reside in a master reference table in
the database I thought it would be easier to append the fields from that
table into new records underlying the subform. From there it would be a
simple matter to add data to the remaining fields.

"strive4peace" wrote:

Hi ridgerunner

yes, it is fine ... but I like to ask anyway so hope you don't mind

If the data is the same every time, how about using the DefaultValue
property of the respective controls? Also, if the user will not
normally change it, then make the TabStop property = No. the user can
always click in to make a change

If the data changes depending on conditions, will those conditions be
the same for that edit session (ie: are they dependent on date?) or will
they change for different records?


Warm Regards,
Crystal

Access Basics
8-part free tutorial that covers essentials in Access
http://www.accessmvp.com/Strive4Peace/Index.htm

*
(: have an awesome day
*



ridgerunner wrote:
I would rather not put my name in a public place if that is OK.

The form would open and autopopulate two fields, same data every time, and
then the data entry person would add the data required for the other fields
in the underlying table. This would speed things up tremendously.
The data would come from two fields in a table located in the same database.

"strive4peace" wrote:

hi ridgerunner (what is your name?)

yes, of course smile

can you describe a bit more about why you want to do this and where the
data would come from?

Warm Regards,
Crystal

Access Basics
8-part free tutorial that covers essentials in Access
http://www.accessmvp.com/Strive4Peace/Index.htm

*
(: have an awesome day
*



ridgerunner wrote:
Is it possible to append new records in a subform, as it opens, to an
underlying table using only certain fields from an existing table?

  #10  
Old May 1st, 2008, 10:05 PM posted to microsoft.public.access.forms
ridgerunner
external usenet poster
 
Posts: 118
Default Append New Records in Subform

Yes, I do want to fill everything out. Thanks. Will this work if I have
referential integrity "on" for the relationship between the master and child
links?

"strive4peace" wrote:

Hi ridgerunner,

"this isn't a survey"

the analogy is the same. I made guesses since you did not specify much.

"Does the "INSERT INTO" add only one record at a time?"

no, it will add all the records from the questions table since there is
no criteria to limit it. I was assuming you would want to fill
everything out...


Warm Regards,
Crystal

Access Basics
8-part free tutorial that covers essentials in Access
http://www.accessmvp.com/Strive4Peace/Index.htm

*
(: have an awesome day
*



ridgerunner wrote:
Thanks, but this isn't a survey; it is an inspection form that is completed
exactly the same way every time an inspection is completed. Does the "INSERT
INTO" add only one record at a time?

"strive4peace" wrote:

creating question records for a survey
~~~

Hi ridgerunner,

thanks for the additional information

since you did not specify fieldnames, I will use what I consider good,
generic names and you will have to change them

I am assuming your database includes tables with a structure similar to
the following:

Participants
- ParticID, autonumber, PK
- Lastname, text
- firstname, text

Questions
- QuestionID, autonumber, PK
- Question, text

Surveys
- SurveyID, autonumber, PK
- ParticID, long, FK to Participants
- SurvDate, date/time

SurveyAnswers
- SurvAnsID, autonumber
- SurveyID, long, fk to Surveys
- QuestionID, long, FK to Questions
- Answer

PK is Primary Key
FK is Foreign Key

this is a simplified example. It does not take into account that you
may have multiple types of surveys with different sets of questions

In SurveyAnswers, make a multi-field unique index on the combination of
SurveyID
QuestionID

this will protect you in case questions are created twice so you do not
get duplicates.

(multi-field unique indexes are covered in Access Basics, link in my siggy)

I am assuming that you have a main form/subform situation where the main
form is based on Surveys and the subform based on SurveyAnswers, which
is the table you wish to automatically fill records in

create a command button on the main form to create the questions

'~~~~~~~~~~~~~~~~~
'save record if changes have been made
if me.dirty then me.dirty = false

'if we are on a new record, give user a message
if me.newrecord then
msgbox "You are not on a current record" _
,, "Cannot create questions"
exit sub
end if

if isnull(me.ParticID) then
msgbox "You must fill out who you are" _
,, "Cannot create questions"
me.ParticID.setFocus
exit sub
end if

dim strSQL as string

strSQL = "INSERT INTO SurveyAnswers (SurveyID, QuestionID) " _
& " SELECT " & me.surveyID _
& ", QuestionID " _
& " FROM Questions;"

'remove this line once everything works ok
debug.print strSQL

currentdb.execute strSQL

'make the new records show up on the subform
me.subform_controlname.requery
'~~~~~~~~~~~~~~~~~

substitute the Name property of your subform control for subform_controlname

'~~~~~~~~~ Compile ~~~~~~~~~

Whenever you change code or references, your should always compile
before executing.

from the menu in a VBE (module) window: Debug, Compile

fix any errors on the yellow highlighted lines

keep compiling until nothing happens (this is good!)

~~~~~~~~~~~~~~~~
** debug.print ***

debug.print strSQL

-- this prints a copy of the SQL statement to the debug window (CTRL-G)

After you execute your code, open the Debug window
CTRL-G to Goto the debuG window -- look at the SQL statement

If the SQL statement has an error

1. Make a new query (design view)

2. choose View, SQL from the menu
(or SQL from the toolbar, first icon)

3. cut the SQL statement from the debug window
(select, CTRL-X)

4. paste into the SQL window of the Query
(CTRL-V)

5. run ! from the SQL window
-- Access will tell you where the problem is in the SQL



Warm Regards,
Crystal

Access Basics
8-part free tutorial that covers essentials in Access
http://www.accessmvp.com/Strive4Peace/Index.htm

*
(: have an awesome day
*



ridgerunner wrote:
There will be 34 records created everytime the form is used. One of the
fields will contain one of five categories and the other field will contain
one of 34 questions. Since the fields reside in a master reference table in
the database I thought it would be easier to append the fields from that
table into new records underlying the subform. From there it would be a
simple matter to add data to the remaining fields.

"strive4peace" wrote:

Hi ridgerunner

yes, it is fine ... but I like to ask anyway so hope you don't mind

If the data is the same every time, how about using the DefaultValue
property of the respective controls? Also, if the user will not
normally change it, then make the TabStop property = No. the user can
always click in to make a change

If the data changes depending on conditions, will those conditions be
the same for that edit session (ie: are they dependent on date?) or will
they change for different records?


Warm Regards,
Crystal

Access Basics
8-part free tutorial that covers essentials in Access
http://www.accessmvp.com/Strive4Peace/Index.htm

*
(: have an awesome day
*



ridgerunner wrote:
I would rather not put my name in a public place if that is OK.

The form would open and autopopulate two fields, same data every time, and
then the data entry person would add the data required for the other fields
in the underlying table. This would speed things up tremendously.
The data would come from two fields in a table located in the same database.

"strive4peace" wrote:

hi ridgerunner (what is your name?)

yes, of course smile

can you describe a bit more about why you want to do this and where the
data would come from?

Warm Regards,
Crystal

Access Basics
8-part free tutorial that covers essentials in Access
http://www.accessmvp.com/Strive4Peace/Index.htm

*
(: have an awesome day
*



ridgerunner wrote:
Is it possible to append new records in a subform, as it opens, to an
underlying table using only certain fields from an existing table?


 




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 08:53 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.