Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Notify User of Duplicate Field Value on After Update? 2

Status
Not open for further replies.

beverlee

Instructor
Oct 8, 2002
61
US
I have a form which includes an Application # that cannot be duplicated. I've set it in the table to be indexed with no duplicates. If a duplicate gets entered on the form, however, it won't alert the user until he/she moves to the next record. Is there a way to alert the user immediately after updating the field so that they don't enter a whole record first? Maybe on the After Update event? Thanks!

 
Take a look at the DLookUp function.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
How are ya beverlee . . . . .

[blue]PHV[/blue] is on target.

In the [blue]BeforeUpdate[/blue] event of [purple]Application#[/purple], try the following. [blue]You![/blue] substitute proper names in [purple]purple[/purple]. Also, if [purple]Application#[/purple] is numeric, [blue]remove the single quotes in the criteria line[/blue].
Code:
[blue]   Dim Msg As String, Style As Integer, Title As String
   Dim DL As String, Criteria As String
   
   DL = vbNewLine & vbNewLine
   Criteria = "[[purple][b]AppFieldName[/b][/purple]]='" & Me![purple][b]AppControlName[/b][/purple] & "'"
   
   If IsNull(DLookup("[[purple][b]AppFieldName[/b][/purple]]", "[purple][b]TableName[/b][/purple]", Criteria)) Then
      Msg = "Application# Already Exists in Database!" & DL & _
            "Duplicates are not allowed . . ." & DL & _
            "Reconsider your data entry and try again . . ."
      Style = vbCritical + vbOKOnly
      Title = "Duplication Application# Error! . . ."
      MsgBox Msg, Style, Title
      Cancel = True
   End If[/blue]

Calvin.gif
See Ya! . . . . . .
 
Thanks for your response. I can't get it to work, however. Here is the code I used:

Dim Msg As String, Style As Integer, Title As String
Dim DL As String, Criteria As String

DL = vbNewLine & vbNewLine
Criteria = "[App#]='" & Me!AppNum & "'"

If IsNull(DLookup("[App#]", "Applications", Criteria)) Then
Msg = "Application# Already Exists in Database!" & DL & _
"Duplicates are not allowed . . ." & DL & _
"Reconsider your data entry and try again . . ."
Style = vbCritical + vbOKOnly
Title = "Duplication Application# Error! . . ."
MsgBox Msg, Style, Title
Cancel = True
End If


Did I goof?
 
1) If App# is defined as numeric in the Applications table then get rid of the single quotes in Criteria.
2) Invert the test:
If Not IsNull(...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
It's not numberic, it's text. A sample Application number is S05-020. ?????
 
Also, I just abbreviated application in [purple]App#[/purple]. You should [blue]change it to the actual name[/blue] if its different!

Calvin.gif
See Ya! . . . . . .
 
Inverting the test worked.....sorry I missed that the first time. You're awesome! Thanks a million! Have a star!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top