Results 1 to 2 of 2
  1. #1
    wasim_sono is offline Advanced Beginner
    Windows XP Access 2013 64bit
    Join Date
    May 2005
    Location
    Pakistan
    Posts
    73

    Apply check at record level

    Dear All



    I want to know that is it possible in VBA to apply check at record level? I explain as that I have an input form which has fields named Consumer, Rec_Date, Amount etc. For avoiding duplicate entry I apply Dlookup function on Consumer field but the requirement is that Rec_Date and amount should also be check for duplicate entry. Means The same Consumer with same Rec_Date and amount should not be entered. Have any one idea about solving the problem? If yes the please write the complete code in VBA for checking.

    Thanks a lot in advance.

    Wasim

  2. #2
    Join Date
    Apr 2007
    Location
    Portsmouth, VA
    Posts
    5
    Insert the following into the form's Before Update event:

    Private Sub Form_BeforeUpdate(Cancel As Integer)
    Dim dbTemp As Database
    Dim rsTemp As DAO.Recordset

    Set dbTemp = CurrentDb()

    Set rsTemp = dbTemp.OpenRecordset("SELECT * FROM tblCustomer" _
    & " WHERE " _
    & "Customer = '" & Me.Customer.Value & "'" _
    & " AND Rec_Date = #" & Format(Me.Rec_Date.Value) & "#" _
    & " AND Amount = " & Str(Me.Amount.Value) _
    )

    If Not rsTemp.EOF Then
    Cancel = MsgBox("You have entered a duplicate value", _
    vbCritical, "Cannot save")
    End If

    rsTemp.Close
    Set rsTemp = Nothing

    End Sub

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 05-29-2014, 09:58 PM
  2. Replies: 0
    Last Post: 04-19-2008, 09:08 PM
  3. Check Box issues
    By data123 in forum Forms
    Replies: 0
    Last Post: 01-03-2007, 03:21 PM
  4. check boxes
    By chiefmsb in forum Forms
    Replies: 1
    Last Post: 11-14-2006, 02:22 PM
  5. Field Level Date validation
    By fadone in forum Forms
    Replies: 1
    Last Post: 12-09-2005, 10:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums