Results 1 to 5 of 5
  1. #1
    hithere is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Sep 2011
    Posts
    63

    Clear Form

    I have a from that will allow users to create new individuals with specs for name, ID, DOB etc. However if the individual's ID is already in use a message box will appear and prevent the user from creating a new file or overwriting the existing one.

    If IsNull(txtID) Then
    MsgBox "Please enter Customer's ID"


    Else
    If DLookup("ID", "tblA", txtID) > 0 Then
    MsgBox " Customer ID already exists" & vbNewLine & " " & vbNewLine & "A duplicate record cannot be created"


    The code accurately premits the duplication of the record but the message continues to show even when the ID is changed to something else. Is there anyway the form can be 'reset' to clear everything out? After the message box appears and ok is selected all the old data still appears on the form. I'll adjust the ID to something else but the message still appears.

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    The Criteria for your DLookup() looks like it is not proper.

  3. #3
    hithere is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Sep 2011
    Posts
    63
    You are actually correct. I got the message box even when I add entry where no ID already exists. Is there anyway to create a lookup to dertermine if an ID/record exists?

  4. #4
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    There is no criteria for the Dlookup() function.
    Maybe try:
    Code:
    If IsNull(txtID) Then
    MsgBox "Please enter Customer's ID"
    Else
    If DLookup("[ID]", "tblA", "[ID] = " & txtID) > 0 Then
       MsgBox "       Customer ID already exists" & vbcrlf & vbcrlf & "A duplicate record cannot be created"
    End if
    BTW, "ID" is not really a good (descriptive) field name. Especially if used in multiple tables. "ID" of what?? CustomerID?? VehicleID?? EmployeeID?? If you had 3 tables: Customer, Vehicle and Employees, all with a field named "ID", it is hard to keep track of what "ID" is being used..

  5. #5
    hithere is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Sep 2011
    Posts
    63
    Thanks Steve. I made the changes you suggested.

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

Similar Threads

  1. How to clear form each time
    By JackieEVSC in forum Forms
    Replies: 1
    Last Post: 10-28-2011, 12:20 PM
  2. How to clear a search form ?
    By Trojnfn in forum Access
    Replies: 2
    Last Post: 10-05-2011, 01:12 PM
  3. Form Fields Clear
    By rajulasb in forum Access
    Replies: 1
    Last Post: 08-06-2011, 01:11 AM
  4. Clear records off of continuous form
    By Ashe in forum Forms
    Replies: 2
    Last Post: 01-04-2011, 12:27 PM
  5. How to clear the form?
    By Mrcams in forum Access
    Replies: 3
    Last Post: 01-03-2011, 12:15 AM

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