By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,583 Members | 617 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,583 IT Pros & Developers. It's quick & easy.

Avoid Creating A Duplicate Record

P: n/a
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
Share this Question
Share on Google+
8 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.