Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check if record exists in table from an unbound form 2

Status
Not open for further replies.

Moss100

Technical User
Aug 10, 2004
586
GB
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
 
Use "AND" in the where condition:

Code:
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
 
Code:
If DCount("App_Status", "tbl_Applicant", _
    "App_Status = 'current' [highlight #FCE94F]AND[/highlight] App_Property_ID_Link = " & txt_App_Property_ID_Link) > 0 Then

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

Duanne beat me to it :)
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.
 
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] = " & [highlight #FCE94F]Me.[/highlight][txt_App_Property_ID_Link]) > 0 Then

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016
 
Thank you kindly - that was exactly what I wanted. On with the project 👍
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top