Results 1 to 15 of 15
  1. #1
    Falahuddin is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Dec 2013
    Location
    Indonesia-Aceh
    Posts
    8

    Validation Rule by relating the data with table

    Dear All,

    With very limitation knowledge I have about Access, I have tried several ways to validate my data with existing table I've developed.



    Actually, I want the access to validate the data (Cellphone number) I've entered in the textbox by looking it in the existing table. So, if the data is there in the table, the message will pop up such as.. "Please continue". But if not, the message should be "this number was not registered yet.." and the textbox will be empty and ready for the new number...

    I wish that you could help me on this matter.. Thank in advance..

    Falah

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    What table is the source of the cell phone numbers? What table is this textbox bound to?

    Options:

    1. Textbox BeforeUpdate event VBA code:
    If IsNull(DLookup("Cell", "table", "Cell='" & Me.textbox & "'")) Then
    MsgBox "This number not registered yet."
    Else
    MsgBox "Please continue"
    End If

    2. combobox
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Falahuddin is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Dec 2013
    Location
    Indonesia-Aceh
    Posts
    8
    Thank for your help. I will try this and let you know... actually the textbox is unbound...

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Why is it not bound? What is purpose of textbox? Have you considered using a combobox?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Falahuddin is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Dec 2013
    Location
    Indonesia-Aceh
    Posts
    8
    The idea is to receive and record certain information through SMS from the cellphone number that already input into the database. So, I wanna do is to validate every message received from the cellphone with the existing number. I will not record the information from the cellphone which is not registered.
    Using Combobox makes me more difficult, since I have search the number one by one.

    I wrote the code you've suggested, and it doesn't work. I realize, some mistakes could be made, since I am a beginner in using VBA. This is what I have written:

    Option Compare Database


    Private Sub NOHP_BeforeUpdate(Cancel As Integer)
    If IsNull(DLookup("no HP", "Tbl_Link1", "no HP=" & Me.NOHP & "")) Then MsgBox "The number is not registered yet..!"
    Else
    MsgBox "Please Continue.."

    End If


    End Sub


    Please give me further advice to solve this problem.. Thanks

  6. #6
    Falahuddin is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Dec 2013
    Location
    Indonesia-Aceh
    Posts
    8
    Hi June..
    After some tries, it works. But, when the number was input incorrect, after the message displayed, the cursor also moved to other cell. It suppose to stay in CELL called "NoHP".

    Again, Please help..

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Try:

    Private Sub NoHP_BeforeUpdate(Cancel As Integer)
    If IsNull(DLookup("Cell", "table", "Cell='" & Me.textbox & "'")) Then
    MsgBox "This number not registered yet."
    Cancel = True
    Me.NoHP = Null
    Else
    MsgBox "Please continue"
    End If
    End Sub
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    Falahuddin is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Dec 2013
    Location
    Indonesia-Aceh
    Posts
    8
    Hi June7...

    Appreciate your quick response to support me. I have tried writing the following code, it display yellow blocked

    Option Compare Database


    Private Sub No_HP_BeforeUpdate(Cancel As Integer)
    If IsNull(DLookup("noHP", "Tbl_Link1", "noHP='" & Me.No_HP & "'")) Then
    MsgBox "The number is not registered yet..!"
    Cancel = True
    Me.No_HP = Null ---->
    Else
    MsgBox "Please Continue.."
    End If
    End Sub

    Need your final advice smoothen this process. .

    Falah

  9. #9
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    It's yellow but what is the exact error message?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  10. #10
    Falahuddin is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Dec 2013
    Location
    Indonesia-Aceh
    Posts
    8
    Here is the message..


    Click image for larger version. 

Name:	Untitled.png 
Views:	12 
Size:	64.8 KB 
ID:	14843

    I hope the image is visible ..

  11. #11
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Is there anything in the Validation Rule property of the textbox?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  12. #12
    Falahuddin is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Dec 2013
    Location
    Indonesia-Aceh
    Posts
    8
    Yes, I used phone number format... Does it disturb...?. Well, actually it's the INPUT MASK, not the VALIDATION RULE...

  13. #13
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Try instead:

    Me.No_HP.Undo
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  14. #14
    Falahuddin is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Dec 2013
    Location
    Indonesia-Aceh
    Posts
    8
    YES... It works now.. Thank you June.. I will find another challenge. Anyway, How to remark this thread as SOLVED...?.

  15. #15
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Thread Tools dropdown above first post - looks like you found it.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Data entry validation rule in Form
    By accessn00bie in forum Access
    Replies: 3
    Last Post: 12-07-2012, 01:11 PM
  2. Validation Rule in Table vs. Form
    By LanieB in forum Forms
    Replies: 2
    Last Post: 03-12-2012, 03:27 PM
  3. Validation Rule
    By rbiggs in forum Forms
    Replies: 4
    Last Post: 08-23-2011, 05:24 PM
  4. Validation Rule
    By Megan in forum Access
    Replies: 1
    Last Post: 11-05-2010, 09:45 AM
  5. Referencing table data in field validation rule
    By toad848 in forum Database Design
    Replies: 3
    Last Post: 03-19-2009, 07:03 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