prevent dupes if

D

deb

I have a form called f40projectMain(PK ProjectID) that has a CONTINUOUS
subform called f4ProjContacts. The form f4ProjContacts uses record source
that is the table t41ContactsProj(PK ProjectID and ContactSubID and
ContactID).

How can i check for dupes if ContactSubID= 48 or 49 and Current field =yes
per ProjectID?
There can be multiple ContactSubID= 48 or 49 if Current field =null or ""
or there can me multiple other ContactSubID's.
The Current field only pertains to ContactSubID 48 or 49 all other
ContactSubID's the Current field will be null or "".

ProjectID................ContactSubID.......ContactID...Current
...1...............................48........................3...............yes
...1...............................49........................4...............yes
...1...............................49........................6...............
...1...............................48........................2...............yes this is a dupe (see below)
...2...............................48........................4...............yes
...2...............................30........................3...............
...2...............................30........................6...............

this is a dupe since there is already a ContactSubID=48 that has Current
=yes for that particular project.
Translated...
ProjectID................ContactSubID.......ContactID...Current
...abc123......................Manager..............Ann...............yes
...abc123......................ProjMgr................Bob...............yes
...abc123......................ProjMgr................Jim...............null
or ""
...abc123......................Manager...............Sue...............yes
this is a dupe
...def345.......................Manager..............Bob................yes
...def345.......................Intern..................Ann...............null or ""
...def345.......................Intern..................Jim...............null or ""

I really need your help!!
 
A

Arvin Meyer [MVP]

An aggregate query ought to do it:

SELECT ContactSubID, Count(ContactSubID) AS TheCount, Current
FROM tblMyData
GROUP BY ContactSubID, Current
HAVING (((Count(ContactSubID))>1) AND ((Current)=True));
 
D

deb

Does this go in the subform's record source?
how does this alert the user that he is trying to enter dupe data?
 
D

deb

I tried your query and it only show two records.

I must not have explained very well. My apologies...

If the user tries to enter another manager(48) and check the Current box,
they should get a message that they can only have one current manager

If the user tries to enter another projmanager(49) and check the Current
box, they should get a message that they can only have one current
projmanager

They can have as many managers or projmanagers or other contacts as they
want but only one of each that have current checked.

Hope that clears up where I neglected to mention.
 
A

Arvin Meyer [MVP]

Build another similar query for the ContactID to find existing duplicates
for that condition.

To check your a possible duplicate before the data is written to the table,
use a recordset, or DLookup to check and see if there is a matching record.
You will need to use 2 separate Recordsets or DLookup statements or
construct an OR condition like:

Dim x
x = DLookUp("[ProjectID]","[tblMyData]","[ProjectID] = " & Form![ProjectID]
& " AND ([ContactSubID] = " & Form![ContactSubID]) & "OR ([ContactID] = " &
Form![ContactID]))
' The above is on a single line.

If IsNull(x) Then
'Do Something
End If
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com
 
D

deb

Where do I put the dlookup?
Should it go under ContactSubID and Current fields before update
or
subform before or after update or currentevent
or
mainform before or after update or currentevent

or a combination?

I do not want the user to be able to exit this record until the dup has been
unselected.

Thank you for all of your help!!
--
deb


Arvin Meyer said:
Build another similar query for the ContactID to find existing duplicates
for that condition.

To check your a possible duplicate before the data is written to the table,
use a recordset, or DLookup to check and see if there is a matching record.
You will need to use 2 separate Recordsets or DLookup statements or
construct an OR condition like:

Dim x
x = DLookUp("[ProjectID]","[tblMyData]","[ProjectID] = " & Form![ProjectID]
& " AND ([ContactSubID] = " & Form![ContactSubID]) & "OR ([ContactID] = " &
Form![ContactID]))
' The above is on a single line.

If IsNull(x) Then
'Do Something
End If
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com


deb said:
I tried your query and it only show two records.

I must not have explained very well. My apologies...

If the user tries to enter another manager(48) and check the Current box,
they should get a message that they can only have one current manager

If the user tries to enter another projmanager(49) and check the Current
box, they should get a message that they can only have one current
projmanager

They can have as many managers or projmanagers or other contacts as they
want but only one of each that have current checked.

Hope that clears up where I neglected to mention.


.
 
A

Arvin Meyer [MVP]

You need to test that all controls are filled:

Put the code inside an If ... Then ... Else statement. Like:

If Len([ProjectID] + [ContactSubID] + [ContactID]) > 0 Then
' Do your lookup
Else
MsgBox "You must fill in all fields", vbOKOnly
Exit Sub
End If

and I would do it in the form's BeforeUpdate event.

--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com


deb said:
Where do I put the dlookup?
Should it go under ContactSubID and Current fields before update
or
subform before or after update or currentevent
or
mainform before or after update or currentevent

or a combination?

I do not want the user to be able to exit this record until the dup has
been
unselected.

Thank you for all of your help!!
--
deb


Arvin Meyer said:
Build another similar query for the ContactID to find existing duplicates
for that condition.

To check your a possible duplicate before the data is written to the
table,
use a recordset, or DLookup to check and see if there is a matching
record.
You will need to use 2 separate Recordsets or DLookup statements or
construct an OR condition like:

Dim x
x = DLookUp("[ProjectID]","[tblMyData]","[ProjectID] = " &
Form![ProjectID]
& " AND ([ContactSubID] = " & Form![ContactSubID]) & "OR ([ContactID] = "
&
Form![ContactID]))
' The above is on a single line.

If IsNull(x) Then
'Do Something
End If
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com


deb said:
I tried your query and it only show two records.

I must not have explained very well. My apologies...

If the user tries to enter another manager(48) and check the Current
box,
they should get a message that they can only have one current manager

If the user tries to enter another projmanager(49) and check the
Current
box, they should get a message that they can only have one current
projmanager

They can have as many managers or projmanagers or other contacts as
they
want but only one of each that have current checked.

Hope that clears up where I neglected to mention.

--
deb


:

An aggregate query ought to do it:

SELECT ContactSubID, Count(ContactSubID) AS TheCount, Current
FROM tblMyData
GROUP BY ContactSubID, Current
HAVING (((Count(ContactSubID))>1) AND ((Current)=True));
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com


I have a form called f40projectMain(PK ProjectID) that has a
CONTINUOUS
subform called f4ProjContacts. The form f4ProjContacts uses record
source
that is the table t41ContactsProj(PK ProjectID and ContactSubID and
ContactID).

How can i check for dupes if ContactSubID= 48 or 49 and Current
field
=yes
per ProjectID?
There can be multiple ContactSubID= 48 or 49 if Current field =null
or
""
or there can me multiple other ContactSubID's.
The Current field only pertains to ContactSubID 48 or 49 all other
ContactSubID's the Current field will be null or "".

ProjectID................ContactSubID.......ContactID...Current
..1...............................48........................3...............yes
..1...............................49........................4...............yes
..1...............................49........................6...............
..1...............................48........................2...............yes
this is a dupe (see below)
..2...............................48........................4...............yes
..2...............................30........................3...............
..2...............................30........................6...............

this is a dupe since there is already a ContactSubID=48 that has
Current
=yes for that particular project.
Translated...
ProjectID................ContactSubID.......ContactID...Current
..abc123......................Manager..............Ann...............yes
..abc123......................ProjMgr................Bob...............yes
..abc123......................ProjMgr................Jim...............null
or ""
..abc123......................Manager...............Sue...............yes
this is a dupe
..def345.......................Manager..............Bob................yes
..def345.......................Intern..................Ann...............null
or ""
..def345.......................Intern..................Jim...............null
or ""

I really need your help!!

--
deb


.


.
 

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

Similar Threads


Top