×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Check if record exists in table from an unbound form
2

Check if record exists in table from an unbound form

Check if record exists in table from an unbound form

(OP)
Hello I wish to check to see if a record exists in a table (to help stop a further record being created).

I have a table called tbl_Applicant. In this are fields App_Status and App_Property_ID_Link

I want to check from an unbound form whether a record exists in tbl_Applicant which has status 'Current' and a App_Property_ID_Link of say 500 (the App_Property_ID_Link will be from a textbox on the form called txt_App_Property_ID_Link).

I have the following working seperately, but can not figure out how to combine the two. Or is there a better way?

CODE -->

If DCount("[App_Status]", "tbl_Applicant", "[App_Status] = 'current' ") > 0 Then
   MsgBox "found"
    Else
    MsgBox "not found"
    End If 

CODE -->

If DCount("[App_Property_ID_Link]", "tbl_Applicant", "[App_Property_ID_Link] = " & [txt_App_Property_ID_Link]) > 0 Then
   MsgBox "found"
    Else
    MsgBox "not found"
    End If 

Many thanks Mark

RE: Check if record exists in table from an unbound form

Use "AND" in the where condition:

CODE --> vba

If DCount("[App_Status]", "tbl_Applicant", "[App_Status] = 'current' AND [App_Property_ID_Link] = " & [txt_App_Property_ID_Link]) > 0 Then 

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016

RE: Check if record exists in table from an unbound form

CODE

If DCount("App_Status", "tbl_Applicant", _
    "App_Status = 'current' AND App_Property_ID_Link = " & txt_App_Property_ID_Link) > 0 Then

    MsgBox "found"
Else
    MsgBox "not found"
End If 

Duanne beat me to it smile
BTW - you don't need all those [ ] if you don't have spaces in the names of your fields, and you are not using reserved words in Access.

---- Andy

There is a great need for a sarcasm font.

RE: Check if record exists in table from an unbound form

I also always include the "Me." to be explicit. It helps me understand later if this is a reference to a form control/field or a memory variable. Your "txt" kinda helps also.

If DCount("[App_Status]", "tbl_Applicant", "[App_Status] = 'current' AND [App_Property_ID_Link] = " & Me.[txt_App_Property_ID_Link]) > 0 Then

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016

RE: Check if record exists in table from an unbound form

(OP)
Thank you kindly - that was exactly what I wanted. On with the project 👍

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close