472,958 Members | 2,109 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

Avoid Creating A Duplicate Record

When my form goes to a new record, I have a procedure that copies the last
record added to the form's underlying table into the form. The intent is that a
series of new records may have the same data in many of the fields so I paste in
the same values of the previous record and then edit what needs edited in the
new record saving much retyping of the same data. Doing this however creates the
definite possibility of creating a duplicate record. If after copying the
previous record, no fields are edited, a duplicate record of the previous record
is created. I'm looking for a way to detect if the new record has been edited
after a copy of the previous record has been added to the form. I checked the
Dirty property and the form is dirt after adding the copy of the previous record
so using the dirty property seems to be out. Does anyone have any idea on what I
can do?

Thanks!

Mark
Nov 12 '05 #1
8 3219
rkc

"Mark" <mm*****@earthlink.net> wrote in message
news:Qb****************@newsread3.news.atl.earthli nk.net...
When my form goes to a new record, I have a procedure that copies the last
record added to the form's underlying table into the form. The intent is that a series of new records may have the same data in many of the fields so I paste in the same values of the previous record and then edit what needs edited in the new record saving much retyping of the same data. Doing this however creates the definite possibility of creating a duplicate record. If after copying the
previous record, no fields are edited, a duplicate record of the previous record is created. I'm looking for a way to detect if the new record has been edited after a copy of the previous record has been added to the form. I checked the Dirty property and the form is dirt after adding the copy of the previous record so using the dirty property seems to be out. Does anyone have any idea on what I can do?

Why are duplicate records allowed in your table? A table should be designed
so that duplicates aren't allowed by the database engine not by the user
interface.

Nov 12 '05 #2
Hi Mark

If you set the values in the new record by setting the DefaultValue for each
control, instead of the Value, then the new record will not become dirty
until the user types in some changes.

The one catch is that the DefaultValue property is always a string
expression, so strings and dates must be enclosed in quote marks.
--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

"Mark" <mm*****@earthlink.net> wrote in message
news:Qb****************@newsread3.news.atl.earthli nk.net...
When my form goes to a new record, I have a procedure that copies the last
record added to the form's underlying table into the form. The intent is that a series of new records may have the same data in many of the fields so I paste in the same values of the previous record and then edit what needs edited in the new record saving much retyping of the same data. Doing this however creates the definite possibility of creating a duplicate record. If after copying the
previous record, no fields are edited, a duplicate record of the previous record is created. I'm looking for a way to detect if the new record has been edited after a copy of the previous record has been added to the form. I checked the Dirty property and the form is dirt after adding the copy of the previous record so using the dirty property seems to be out. Does anyone have any idea on what I can do?

Thanks!

Mark

Nov 12 '05 #3
Graham,

Thank you for the response!

Would you explain further your last sentence about the DefaultValue property is
always a string expression?

If I wanted the following default values in different fields, what would I set
the DefaultValue to:
4.5
$8.75
5/10/04
Miles Shipping Company

Thanks,

Mark
"Graham Mandeno" <Gr************@nomail.please> wrote in message
news:ei**************@tk2msftngp13.phx.gbl...
Hi Mark

If you set the values in the new record by setting the DefaultValue for each
control, instead of the Value, then the new record will not become dirty
until the user types in some changes.

The one catch is that the DefaultValue property is always a string
expression, so strings and dates must be enclosed in quote marks.
--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

"Mark" <mm*****@earthlink.net> wrote in message
news:Qb****************@newsread3.news.atl.earthli nk.net...
When my form goes to a new record, I have a procedure that copies the last
record added to the form's underlying table into the form. The intent is

that a
series of new records may have the same data in many of the fields so I

paste in
the same values of the previous record and then edit what needs edited in

the
new record saving much retyping of the same data. Doing this however

creates the
definite possibility of creating a duplicate record. If after copying the
previous record, no fields are edited, a duplicate record of the previous

record
is created. I'm looking for a way to detect if the new record has been

edited
after a copy of the previous record has been added to the form. I checked

the
Dirty property and the form is dirt after adding the copy of the previous

record
so using the dirty property seems to be out. Does anyone have any idea on

what I
can do?

Thanks!

Mark


Nov 12 '05 #4
Good point!

The table has 27 fields. Should I set each field to No Duplicates? How do I trap
the error if the record I am trying to enter is a duplicate?

Thanks,

Mark
"rkc" <rk*@yabba.dabba.do.rochester.rr.bomb> wrote in message
news:TA********************@twister.nyroc.rr.com.. .

"Mark" <mm*****@earthlink.net> wrote in message
news:Qb****************@newsread3.news.atl.earthli nk.net...
When my form goes to a new record, I have a procedure that copies the last
record added to the form's underlying table into the form. The intent is

that a
series of new records may have the same data in many of the fields so I

paste in
the same values of the previous record and then edit what needs edited in

the
new record saving much retyping of the same data. Doing this however

creates the
definite possibility of creating a duplicate record. If after copying the
previous record, no fields are edited, a duplicate record of the previous

record
is created. I'm looking for a way to detect if the new record has been

edited
after a copy of the previous record has been added to the form. I checked

the
Dirty property and the form is dirt after adding the copy of the previous

record
so using the dirty property seems to be out. Does anyone have any idea on

what I
can do?

Why are duplicate records allowed in your table? A table should be designed
so that duplicates aren't allowed by the database engine not by the user
interface.

Nov 12 '05 #5
Hi Mark,

Wanting to carry current values forward to the next record is fairly common.
Someone else posted a similar question in microsoft.public.access My reply
follows

==============================================
Hi Maggie,

Put the following in the AfterUpdate event of your form

Const CQuote = """" 'that's two quotes, 4 quote marks

Me!txtExamDate.DefaultValue = CQuote & Me!txtExamDate.Value & CQuote

If you're going to use this code on more than one form I'd make CQuote a
global constant. Otherwise it can go in the declarations area of the
subroutine

As you can see, if you have several TextBoxes that you want to hold the
current value as the default just keep copying the Me!txtExamDate ... line
and always change the name appropriately.

Shame on me, I've lost the thread of attribution but I believe Allen Browne
posted the code.

================================================== ======
HTH
--
-Larry-
--

"Mark" <mm*****@earthlink.net> wrote in message
news:ZE***************@newsread2.news.atl.earthlin k.net...
Graham,

Thank you for the response!

Would you explain further your last sentence about the DefaultValue property is always a string expression?

If I wanted the following default values in different fields, what would I set the DefaultValue to:
4.5
$8.75
5/10/04
Miles Shipping Company

Thanks,

Mark
"Graham Mandeno" <Gr************@nomail.please> wrote in message
news:ei**************@tk2msftngp13.phx.gbl...
Hi Mark

If you set the values in the new record by setting the DefaultValue for each control, instead of the Value, then the new record will not become dirty
until the user types in some changes.

The one catch is that the DefaultValue property is always a string
expression, so strings and dates must be enclosed in quote marks.
--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

"Mark" <mm*****@earthlink.net> wrote in message
news:Qb****************@newsread3.news.atl.earthli nk.net...
When my form goes to a new record, I have a procedure that copies the last record added to the form's underlying table into the form. The intent is
that a
series of new records may have the same data in many of the fields so
I paste in
the same values of the previous record and then edit what needs edited
in the
new record saving much retyping of the same data. Doing this however

creates the
definite possibility of creating a duplicate record. If after copying
the previous record, no fields are edited, a duplicate record of the

previous record
is created. I'm looking for a way to detect if the new record has been

edited
after a copy of the previous record has been added to the form. I
checked the
Dirty property and the form is dirt after adding the copy of the
previous record
so using the dirty property seems to be out. Does anyone have any idea
on what I
can do?

Thanks!

Mark



Nov 12 '05 #6
rkc

"Mark" <mm*****@earthlink.net> wrote in message
news:IH***************@newsread2.news.atl.earthlin k.net...
Good point!

The table has 27 fields. Should I set each field to No Duplicates? How do I trap the error if the record I am trying to enter is a duplicate?


In general you would identify the field or combination of fields that make
a record unique and create a unique index on the field(s). That way the
Jet engine won't allow a duplicate record to be entered. If a duplicate
record is submitted for some reason there will be a popup message
informing you of it, but I wouldn't call it an error since it is not fatal
to
the application.

Nov 12 '05 #7
In this case, a duplicate record is one where all 27 fields match an existing
record. A new record could have 26 fields match an existing record and one field
not match. That is not a duplicate. The one field could be any of the 27. For
this reason, I can't set any field to No Duplicates.

Mark
"rkc" <rk*@yabba.dabba.do.rochester.rr.bomb> wrote in message
news:kj*******************@twister.nyroc.rr.com...

"Mark" <mm*****@earthlink.net> wrote in message
news:IH***************@newsread2.news.atl.earthlin k.net...
Good point!

The table has 27 fields. Should I set each field to No Duplicates? How do

I trap
the error if the record I am trying to enter is a duplicate?


In general you would identify the field or combination of fields that make
a record unique and create a unique index on the field(s). That way the
Jet engine won't allow a duplicate record to be entered. If a duplicate
record is submitted for some reason there will be a popup message
informing you of it, but I wouldn't call it an error since it is not fatal
to
the application.

Nov 12 '05 #8
Hi Mark

I hope Larry's response has answered your question.

To further elaborate, the DefaultValue property is seen as a string which is
then evaluated as an expression. For example:
MyControl.DefaultValue = "Date()"
would cause the Date function to be called, which would return the current
date.

Similarly,
MyControl.DefaultValue = "8/1/04"
would cause the string to be evaluated as the expression "8 divided by 1
divided by 4", which would return the result 2.

Presumably this would NOT be what was intended. To get the intended result,
put the string in quotes:
MyControl.DefaultValue = """8/1/04"""

Or, to make this more readable, use Larry's suggestion and declare a
constant for the quote character:
Const cQuote = """"
MyControl.DefaultValue = cQuote & "8/1/04" & cQuote

For what you want to do, your default values will be derived from variables
(or recordset fields), not constants, so you might do something like this:
With Me.RecordsetClone
.MoveLast
Me.Field1.DefaultValue = cQuote & .Field1 & cQuote
Me.Field2.DefaultValue = cQuote & .Field2 & cQuote
... etc
End With

You can also use the Form_AfterUpdate procedure to set change default values
to the new data as new records are added.

(Note that some sources suggest you enclose dates in hash signs (#), but I
recommend quotes as preferable because the conversion of a quoted date will
respect your regional date format settings, while #8/1/04# will always be
interpreted as the US format of mm/dd/yy)

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand
you could set the DefaultValue of a textbox to "Da
"Mark" <mm*****@earthlink.net> wrote in message
news:ZE***************@newsread2.news.atl.earthlin k.net...
Graham,

Thank you for the response!

Would you explain further your last sentence about the DefaultValue property is always a string expression?

If I wanted the following default values in different fields, what would I set the DefaultValue to:
4.5
$8.75
5/10/04
Miles Shipping Company

Thanks,

Mark
"Graham Mandeno" <Gr************@nomail.please> wrote in message
news:ei**************@tk2msftngp13.phx.gbl...
Hi Mark

If you set the values in the new record by setting the DefaultValue for each control, instead of the Value, then the new record will not become dirty
until the user types in some changes.

The one catch is that the DefaultValue property is always a string
expression, so strings and dates must be enclosed in quote marks.
--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

"Mark" <mm*****@earthlink.net> wrote in message
news:Qb****************@newsread3.news.atl.earthli nk.net...
When my form goes to a new record, I have a procedure that copies the last record added to the form's underlying table into the form. The intent is
that a
series of new records may have the same data in many of the fields so
I paste in
the same values of the previous record and then edit what needs edited
in the
new record saving much retyping of the same data. Doing this however

creates the
definite possibility of creating a duplicate record. If after copying
the previous record, no fields are edited, a duplicate record of the

previous record
is created. I'm looking for a way to detect if the new record has been

edited
after a copy of the previous record has been added to the form. I
checked the
Dirty property and the form is dirt after adding the copy of the
previous record
so using the dirty property seems to be out. Does anyone have any idea
on what I
can do?

Thanks!

Mark



Nov 12 '05 #9

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

Similar topics

1
by: Robert | last post by:
How can I query an existing table and update a field in each record in the table with the occurrence count of each record e.g. update field to 1 (= first record occurrence), update field to 2 for...
3
by: Nhmiller | last post by:
I searched here for an answer. I am entering records into a database, and it would save a lot of time if I could duplicate a record that is very similar to the new one I am about to enter, then...
6
by: planetthoughtful | last post by:
Hi All, I have a C# ASP.NET page that submits back to itself to insert details from a form into a database table. When / if the user refreshes the page (and gets the standard warning that POST...
1
by: OxfordConsult | last post by:
Hello, I have created a form that links with a table with the autonumber feature as its primary key. Whenever i create a new record in the form (using a command button ... i have disabled the...
5
by: KewlToyZ | last post by:
Good day, I am stuck in a strange situation. SQL 2000 Server, creating a stored procedure to use in Crystal Reports 11. I am trying to build a report without creating a table or temprorary table in...
5
by: ramab | last post by:
Hi. There are two fields in my table that i check so that both of them doesnt occur together again to create a duplicate record. My problem is that if one of the field loses focus then i am able to...
2
by: jakeesgirl | last post by:
I'm new to c# and am creating a program in visual studio. I have several different forms in the program. Some of these forms need to access the same form. But I need to pass "this" to the form. ...
3
by: smugcool | last post by:
HI, I am having a database in access. Where user imports various data which is in excel format. I want them to stop importing any duplicate record. If any duplicate record is been trying to import...
1
by: xraive | last post by:
I have a problem with this. Currently I am trying Allen's code and i am not successful. Current Design Table1 (Main Form) TravelID (PK) ApprovedBY EntreredBy BudgetCode ExpenseCode
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.