Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2004

    Unanswered: checking primary key violation instantly..

    By default ms access prompts the user of primary key violation when a record is going to be added in the database e.g. on clicking the add button. My question is that how can a user be prompted on an entry which possibly violates Primary key violation as soon as he 'leaves' the primary key Field (e.g. by pressing tab/enter, etc)?

  2. #2
    Join Date
    Sep 2003
    The extremely Royal borough of Kensington, London
    Private Sub textfield1_LostFocus()
    Dim str As String
    str = "Select id from table where id = "& param &""
    If (condition) Then
    MsgBox "Primary Key Violation"
    End If
    End Sub

    condition = True, if resultSet is not empty.
    Last edited by r123456; 02-26-04 at 07:50.
    Bessie Braddock: Winston, you are drunk!
    Churchill: And Madam, you are ugly. And tomorrow, I'll be sober, and you will still be ugly.

  3. #3
    Join Date
    Feb 2004
    I use the BeforeUpdate event so you can cancel the event...

    Private Sub Text1_BeforeUpdate(Cancel As Integer)
    If DCount("*", "tblLookup", "[textID] = '" & Text1 & "'") <> 0 Then
    Cancel = True
    MsgBox "Value already exists: " & Text1
    End If
    Exit Sub

  4. #4
    Join Date
    Feb 2004
    Thanks r123456 and glnstanley for all the help.. had it done glnstanley's way

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts