Results 1 to 5 of 5

Thread: no repeat (2k)

  1. #1
    2 Star Lounger
    Join Date
    Nov 2002
    Posts
    160
    Thanks
    0
    Thanked 0 Times in 0 Posts

    no repeat (2k)

    i have a tbl that incloude 2 feal the 1st is id & date , id is a key , if i enter id=1111 it accept if i enter it again it not accept , that is ok but i want to accept if the date is not the same ( 1111>>>> 1/1/03 also 11115/1/03 )
    Ashraf

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: no repeat (2k)

    It sounds like you have the ID field indexed with no duplicates allowed. If you want the key to be the combination of ID and the date field (you shouldn't use "date" as a field name in Access), then you need to remove the index from the ID field and set the primary key or a unique key on the two fields together.
    Charlotte

  3. #3
    2 Star Lounger
    Join Date
    Nov 2002
    Posts
    160
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: no repeat (2k)

    Thank u very much it work good but if i can put a massgae told me that ID is found befroe .
    Ashraf

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: no repeat (2k)

    You can write code in the Before Update event of the ID control or of the form to check if the ID already occurs.
    Another good place to check this is in the On Error event of the form. The event handler has two arguments:
    DataErr is the error number of the error that occurred
    Response can be set by the programmer to one of these values:
    <UL><LI>acDataErrContinue: the error has been handled or reported by the programmer.
    <LI>acDataErrDisplay: Access should display the built-in error message[/list]The error that occurs if the user tries to enter a duplicate key is 3022, and the error that occurs if the user leaves the primary key blank is 3058. So you could create the following event handler for the On Error event of the form:

    Private Sub Form_Error(DataErr As Integer, Response As Integer)
    Select Case DataErr
    Case 3022
    MsgBox "You have tried to enter an ID that already occurred", vbExclamation
    ID = Null
    ID.SetFocus
    Case 3058
    MsgBox "You can't leave the ID empty", vbExclamation
    ID.SetFocus
    Case Else
    MsgBox DataErr & AccessError(DataErr), vbExclamation
    End Select
    Response = acDataErrContinue
    End Sub

  5. #5
    2 Star Lounger
    Join Date
    Nov 2002
    Posts
    160
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: no repeat (2k)

    Thank u Hans it work good .
    Ashraf

Posting Permissions

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