Prevent duplicate and certain types of entries

  • Thread starter Datacruz via AccessMonster.com
  • Start date
D

Datacruz via AccessMonster.com

I have a sub form that has "Enddate" and 5 Boolean option 1 through 5 named
"Account numbers". I want to prevent duplicates by date and option accounts
but also restrict entries from being entered. Case in point if I enter
"Enddate" and option 1 I can not enter date and option 3 or 4. I have
reviewed all help files and sort of understand the following code. What would
I do to modify it to meet the requirements?
Private Sub ID_BeforeUpdate(Cancel As Integer)
Dim strMsg As String

If IsNull(Me.ID) OR (Me.ID = Me.ID.OldValue) Then
'Do nothing: it's not a duplicate of itself.
Else
If Not IsNull(DLookup("ID", "Table1", "ID = " & Me.ID)) Then
Cancel = True
strMsg = "You already have that value." & vbCrLf & _
"Enter another value, or press Esc to undo."
MsgBox strMsg, vbExclamation, "Duplicate value!"
End If
End If
End Sub
 
D

Daryl S

Datacruz -

If you only want to allow one entry per date, then the proper way would be
to have a unique key on the date field in the underlying table.
 
D

Datacruz via AccessMonster.com

I should explain better. I am allowed up to three entries for the same date.
So Enddate would have three separate entries and have a unique key but with a
different Boolean option selected. So if Enddate is 12/1/09 with the Boolean
option No 1 is selected this entry could not be duplicated but the next
Enddate entry of the same date would not allow option No 4 and 6 to be
selected.
Daryl said:
Datacruz -

If you only want to allow one entry per date, then the proper way would be
to have a unique key on the date field in the underlying table.
I have a sub form that has "Enddate" and 5 Boolean option 1 through 5 named
"Account numbers". I want to prevent duplicates by date and option accounts
[quoted text clipped - 16 lines]
End If
End Sub
 
D

Daryl S

You could put a unique key on the combination of Enddate and the boolean
fields, which would prevent any duplication.

--
Daryl S


Datacruz via AccessMonster.com said:
I should explain better. I am allowed up to three entries for the same date.
So Enddate would have three separate entries and have a unique key but with a
different Boolean option selected. So if Enddate is 12/1/09 with the Boolean
option No 1 is selected this entry could not be duplicated but the next
Enddate entry of the same date would not allow option No 4 and 6 to be
selected.
Daryl said:
Datacruz -

If you only want to allow one entry per date, then the proper way would be
to have a unique key on the date field in the underlying table.
I have a sub form that has "Enddate" and 5 Boolean option 1 through 5 named
"Account numbers". I want to prevent duplicates by date and option accounts
[quoted text clipped - 16 lines]
End If
End Sub

--



.
 

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