Results 1 to 3 of 3
  1. #1
    joeshig is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2017
    Location
    Warwickshire
    Posts
    4

    Control Source: Check if a text box in a form exists in a database table.

    Hi,




    I have been looking around for a while now but cannot seem to get this question answered.


    In access I have a form with a blank text box, in this blank text box I would like it to check whether the contents of another text box (called txtReg) on the same form exists in a database table.

    If it does exist, I would like it to show the work 'Covered'.

    Is this possible, I've have numerous tries at using DLookup but to no avail?

    Thanks

  2. #2
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Dlookup is the right way to go. In the AfterUpdate event of the first textbox, do your DLookup and populate the second text accordingly.

  3. #3
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,511
    Put this code in the OnCurrent event of the form. (Change names of fields and tables below to yours.) Assuming value in txtReg on form is text. If a number look at the link to change the syntax.

    If Not Isnull(DLookup("FieldInYourTable", "YourTable", "txtReg = '" & Me.txtReg & "'")) then
    Me.YourTextBox = "Covered"
    Else
    Me.YourTextBox = "Not Covered"
    End If


    DLoookUp Info:
    http://access.mvps.org/access/general/gen0018.htm

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

Similar Threads

  1. Check If Form Value Already Exists In Database
    By Richard_Marx in forum Modules
    Replies: 9
    Last Post: 08-15-2016, 09:32 AM
  2. Replies: 33
    Last Post: 09-16-2014, 12:47 PM
  3. Replies: 1
    Last Post: 04-23-2013, 03:35 PM
  4. Control Source on Form Reading Value in Table
    By hammer187 in forum Forms
    Replies: 1
    Last Post: 10-23-2012, 02:43 PM
  5. How to check if Table already exists
    By riaarora in forum Access
    Replies: 1
    Last Post: 08-12-2012, 09:48 AM

Tags for this Thread

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