Create New Entry From Exisiting Data

J

jmllr24

If someone can help with this I would be very appreciative.

Ill try to explain using a simple version of what I would like to do.

My switchboard has two options.

1. Create a new entry
2. Create an entry from an existing entry

When you click create a new entry a form opens (Form A). This form
automatically assigns an ID number. It also asks the user to enter in a
persons Name and Car they Drive.

This information is then stored in a table in the following way
ID Name Car
1 Jon Toyota
2 Jane Honda
etc...

The second part is where I am having trouble figuring out what to do.
When you click "Create an entry from an existing" I would like a form to pop
up that asks the user to enter in an ID number. Then, for example a user
enters in the number 2 and then clicks an "Enter" button.

Once the button is clicked "Form A" opens but automatically populates the
fields with data from ID 2. Additionally a new ID number is assigned, so in
this case ID 3 would have Jane , Honda in it.

Sorry if this is confusing. Please let me know if additional information is
required. Thank you so much.
 
B

Beetle

Why?

As in, why do you think you need to redundantly store the same
data over and over again in your table? Perhaps if you can
provide some more insight into what you are trying to do and why
you think you need to do it that way, someone here can give you
some advice as to the correct approach.
 
J

John W. Vinson

If someone can help with this I would be very appreciative.

Ill try to explain using a simple version of what I would like to do.

My switchboard has two options.

1. Create a new entry
2. Create an entry from an existing entry

When you click create a new entry a form opens (Form A). This form
automatically assigns an ID number. It also asks the user to enter in a
persons Name and Car they Drive.

This information is then stored in a table in the following way
ID Name Car
1 Jon Toyota
2 Jane Honda
etc...

The second part is where I am having trouble figuring out what to do.
When you click "Create an entry from an existing" I would like a form to pop
up that asks the user to enter in an ID number. Then, for example a user
enters in the number 2 and then clicks an "Enter" button.

Once the button is clicked "Form A" opens but automatically populates the
fields with data from ID 2. Additionally a new ID number is assigned, so in
this case ID 3 would have Jane , Honda in it.

Sorry if this is confusing. Please let me know if additional information is
required. Thank you so much.

I'm in full agreement with Beetle's question... but if there is in fact a good
reason to do this, the button should run an Append query such as

INSERT INTO tablename
SELECT [Name], [Car]
FROM tablename
WHERE [ID] = [Forms]![YourFormName]![txtID]
 
J

jmllr24

Thanks for responding back so quickly.

To answer the why question.

The form I have is more complicated than the example. So the reason to use
redundant data is just to make things easier. Basically one entry may have
all the same information in it except for two or three fields. In that case
it's easier to have the form populate with another entries information and
then a user can edit specific fields.

Thanks again.

John W. Vinson said:
If someone can help with this I would be very appreciative.

Ill try to explain using a simple version of what I would like to do.

My switchboard has two options.

1. Create a new entry
2. Create an entry from an existing entry

When you click create a new entry a form opens (Form A). This form
automatically assigns an ID number. It also asks the user to enter in a
persons Name and Car they Drive.

This information is then stored in a table in the following way
ID Name Car
1 Jon Toyota
2 Jane Honda
etc...

The second part is where I am having trouble figuring out what to do.
When you click "Create an entry from an existing" I would like a form to pop
up that asks the user to enter in an ID number. Then, for example a user
enters in the number 2 and then clicks an "Enter" button.

Once the button is clicked "Form A" opens but automatically populates the
fields with data from ID 2. Additionally a new ID number is assigned, so in
this case ID 3 would have Jane , Honda in it.

Sorry if this is confusing. Please let me know if additional information is
required. Thank you so much.

I'm in full agreement with Beetle's question... but if there is in fact a good
reason to do this, the button should run an Append query such as

INSERT INTO tablename
SELECT [Name], [Car]
FROM tablename
WHERE [ID] = [Forms]![YourFormName]![txtID]
 
J

John W. Vinson

The form I have is more complicated than the example. So the reason to use
redundant data is just to make things easier. Basically one entry may have
all the same information in it except for two or three fields. In that case
it's easier to have the form populate with another entries information and
then a user can edit specific fields.

I figured, but if there are several repeated fields and several unique fields
it *sounds* like you should consider normalizing into two or more tables. Hard
to say though; you know your data better than I do, obviously!
 
L

Larry Daugherty

jmllr24,

You've already gotten good input from Sean and John. Both have
already directly suggested or alluded to what I believe is the *real*
problem: Your schema is incorrect.

Please understand that everything entered here is intended for yur
benefit (and that of hundreds of people who lurk and learn) and none
of it should be construed as a put-down.

It is a truism in the Access world that the essence of good design
begins with good data design, i.e. your schema. In simple terms, the
design of your Tables and the Relationships between them constitute
your schema.

Get the schema down correctly and you will be able to create an
application that can be implemented easily and cost effectively.
Further, that correct schema will enable further modification and
enhancement to meet new needs as the business environment or the
business focus changes.

Get the schema wrong and your application will be difficult and
expensive (in time and effort and lost opportunities) to implement,
maintain and enhance.

My guess, admittedly a pre-judgement, is that you are currently
enmeshed in the latter paradigm.

Your schema should be modeled on the real-world universe of entities
and the relationships between them and events you are tracking or
controlling with your application. Once the entities and the relevant
data elements are identified you can begin the process of Normalizing
your data.

Like John, I believe that just the part of your existing schema that
you have revealed would benefit by putting those columns that *always*
repeat for a given set of records into a table and then creating one
or more related tables to deal with the unique information in each
related record. That concept is one of the major hallmarks or a
Relational Database system.

With your schema altered as above it's easy to manage your data entry
by using the Form/SubForm paradigm. There is ample information in the
Help file to help you through that process once you have a correct
schema. You can always post back if you have difficulties. That's
why we're here.

While the whole concept suggested above may seem foreign, awkward and
intimidating, once you have traveled that path and reaped the
benefits, it will become second nature to design your schema that way
and to massage your data using the Form/SubForm paradigm.

If you are going to play with your existing design and data, start by
making a backup copy or two before you begin.

Inferring without facts, I'll try an example:

I assume that the table into which you are entering data has the sense
of "Head of Household" or "Paying Customer" and could contain all of
the data that always repeats in your current schema. (Normalizing to
3rd Normal Form may change a few things). Refer to that table as
"tblCustomer". Let's assume that the unique data comes down to
identifying the individual family member and their car. Leave the
possibility of more than one car per member to a later discussion.
Lets refer to that table as "tblMemberCar". Assuming Autonumber
primary keys, tblMemberCar will have all of the unique data you expect
to find there and will have an additional a long integer field with
the same name as the Primary Key of tblCustomer.

Once your tables are designed, open the Relationships window, bring up
the two tables under discussion, Select tblCustomer.CustomerID and
draw a line to tblMemberCar.Customer. Doubleclick the link just
established and enable Referential Integrity. Enable Automatic
Updates and Cascade Deletes.

Note, all design dimensions in the forms and controls will be
tweakable after you have established working parameters.

Design a new form based on tblCustomer. Give it name like
"frmCustomerData" and a title like "Customer Data". That will be the
data entry form for entering and managing the relevant customer data.
Default view is "Single".

Place your new form in Run Mode and enter at least three *Customer*
records. Make these as near the real information as possible.

Copy the form above with the name "frmManageMemberCar" and a title
like "Member Data". Delete all of the controls except those that help
to identify this customer. Usually that would come down to something
like the customer's full name and primary account number with you.
Turn on that form's Header and Footer. Drag the bottom of the Header
down about 1/4". With Wizards turned on in the Toolbox, Click the
Combobox icon and then draw a combobox control from about 1/3 of the
way across to about 3/4 across. The Wizard will ask what you want to
do. Choose the option to go to a specific record. In the Label for
the new combobox insert "Find Customer". Name the combobox
"cboFindCustomer". To test just this much of your design, place this
form in Run Mode and try selecting from the Customer records you
entered earlier. Each time you select a different record and release
the mouse, the form should display data from that record.

Design a new form based on tblMemberCar. I give forms designed to be
subfomrs the prefix "suf". I would name this form "sufMemberCar".
Default view is "Continuous". For this example make sure that Show
Header and Footer is Off. If possible, design the new form to show a
complete record in a single line across the form. Design the detail
section of the form to take just a little more vertical space than is
required to show the data in the controls. The idea is to eventually
achieve something that looks very much like a Datasheet but that
provides more functionality and protection. Close your form.

You are now at the point where you can place frmManageMemberCar in
design mode such that the entire form takes less than half the screen
and the detail section is in view when you open the Database|:Forms
window. Click and drag sufMemberCar into the detail section of
frmManageMemberCar.. Access Help used to be pretty good in this area
and probably still is.

If all went well you have something that you can tweak to your
satisfaction. If not, post back with a specific issue and someone
will pick up the thread. If my inferences were anywhere close to the
mark then you should have something that will be much more user
friendly than your current implementation. You should also not find a
need to enter redundant data.

There are a few real-world situations in which it is viable to enter
redundant data. Yours does not appear to be one of those. More than
anything else it looks like "committing spreadsheet". Excel is a
premier spreadsheet development and management platform. Access is
*the* premier RAD application development and management platform.
Access and Excel are *not* flawed versions of each other. They have
different platform goals and different means of achieving them.


Reproduced below is a useful list of resources that John often
includes that would very likely be valuable to you.

Jeff Conrad's resources page:
http://www.accessmvp.com/JConrad/accessjunkie/resources.html

The Access Web resources page:
http://www.mvps.org/access/resources/index.html

Roger Carlson's tutorials, samples and tips:
http://www.rogersaccesslibrary.com/

A free tutorial written by Crystal:
http://allenbrowne.com/casu-22.html

A video how-to series by Crystal:
http://www.YouTube.com/user/LearnAccessByCrystal

MVP Allen Browne's tutorials:
http://allenbrowne.com/links.html#Tutorials


HTH
 
J

jmllr24

Thanks. I think we're getting closer to figuring out a solution.

Hopefully I can clarify this more. Thanks for baring with me.

Just as a side note, currently everytime a user enters information and
records an entry an ID number is automatically assigned to it. This ID # just
counts up sequentially everytime.

Lets say for example the last entry that was recorded in the database is all
linked to ID # 15.

A user then wants to add in another entry. This new entry will have an ID #
16.

This new entry will contain almost all the same information as ID #15 has.

Because of this, the entry process can be performed at a much quicker rate
if a user has the option to enter in a text box the number 15 then click a
button that opens the entry form and contains all the data that was linked to
ID #15 but is now automatically assigned to an ID # 16. (Basically this
option is to help people that are slow typers)

Here is the code I currently have which is pretty standard as it was created
using the wizard. This code allows the user to enter in an ID number, click
the button, and then a form opens up with all the information linked to the
entered ID. However, this is not what I would like to occur. I want the
button to do what I described above:
---------------------------------------------------------------------------------------
Private Sub CreateFromExisting_CMD_Click()
On Error GoTo Err_CreateFromExisting_CMD_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "WorkOrderData_Form"

stLinkCriteria = "[ID]=" & Me![Text2]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_CreateFromExisting_CMD_Click:
Exit Sub

Err_CreateFromExisting_CMD_Click:
MsgBox Err.Description
Resume Exit_CreateFromExisting_CMD_Click

End Sub
 
J

jmllr24

Ok So I Think I'm Really Close. I changed my code to the following. Basically
I tried to insert only one field [Part Name] for now to keep things simple
until it starts to work. But its not working properly. Right now if you enter
in the #15 and click the button it opens the form using all the data from the
first entry (ID # 1). I'm not sure why this is happening. Please help.

Just to clear up what my names are:
WorkOrderData_Form is the form where a user enters in info and adds a record
WorkOrderData is the table where this information is stored.
Text 2 is where a user enters in an ID # such as 15 to indicate it wants to
create a new entry using data linked to ID # 15.
[Part Name] is the one field of info I want to automatically populate in the
next entry , ie ID # 16

Private Sub CreateFromExisting_CMD_Click()
On Error GoTo Err_CreateFromExisting_CMD_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "WorkOrderData_Form"

strLinkCriteria = "INSERT INTO WorkOrderData_Form VALUES [Part Name] From
WorkOrderData Where [ID] = [Forms]![Create From Existing][Text2]"

DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_CreateFromExisting_CMD_Click:
Exit Sub

Err_CreateFromExisting_CMD_Click:
MsgBox Err.Description
Resume Exit_CreateFromExisting_CMD_Click

End Sub

jmllr24 said:
Thanks. I think we're getting closer to figuring out a solution.

Hopefully I can clarify this more. Thanks for baring with me.

Just as a side note, currently everytime a user enters information and
records an entry an ID number is automatically assigned to it. This ID # just
counts up sequentially everytime.

Lets say for example the last entry that was recorded in the database is all
linked to ID # 15.

A user then wants to add in another entry. This new entry will have an ID #
16.

This new entry will contain almost all the same information as ID #15 has.

Because of this, the entry process can be performed at a much quicker rate
if a user has the option to enter in a text box the number 15 then click a
button that opens the entry form and contains all the data that was linked to
ID #15 but is now automatically assigned to an ID # 16. (Basically this
option is to help people that are slow typers)

Here is the code I currently have which is pretty standard as it was created
using the wizard. This code allows the user to enter in an ID number, click
the button, and then a form opens up with all the information linked to the
entered ID. However, this is not what I would like to occur. I want the
button to do what I described above:
---------------------------------------------------------------------------------------
Private Sub CreateFromExisting_CMD_Click()
On Error GoTo Err_CreateFromExisting_CMD_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "WorkOrderData_Form"

stLinkCriteria = "[ID]=" & Me![Text2]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_CreateFromExisting_CMD_Click:
Exit Sub

Err_CreateFromExisting_CMD_Click:
MsgBox Err.Description
Resume Exit_CreateFromExisting_CMD_Click

End Sub
------------------------------------------------------------------------------------------

Again thank you for your time.


John W. Vinson said:
I figured, but if there are several repeated fields and several unique fields
it *sounds* like you should consider normalizing into two or more tables. Hard
to say though; you know your data better than I do, obviously!
 
J

John W. Vinson

A user then wants to add in another entry. This new entry will have an ID #
16.

This new entry will contain almost all the same information as ID #15 has.

I'd suggest a far simpler way to accomplish this, with no button and almost no
code.

In the AfterUpdate event of each control that will ordinarily get repeated
values, put:

Private Sub controlname_AfterUpdate()
Me!controlname.DefaultValue = Chr(34) & Me!controlname & Chr(34)
End Sub

using the actual control name of course.

This will make entries "sticky" - the default value for the control will be
whatever the user entered in the previous record. This can be overtyped when
and if the needed entry changes.

My concern about the normalization of your data is still strong, however. I
can imagine cases where you will have one entity which *often* has repeated
values, but I really suspect that you have more than one entity in a one to
many relationship.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top