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!

How do I find out if a record exists?

Status
Not open for further replies.

modalman

Programmer
Feb 14, 2001
156
GB
Can anyone deliver me from this seemingly very simple problem? I have created a database application using Access and Form A needs to open either Form B or Form C depending on whether a particualr record exists or not. I have messed about with VB, RunSQL and DoCmd etc. I have also tried to create a recordset but it wont accept 'Dim dbs As Database' and 'Dim rs As Recordset'. I would really appreciate some guiding advice. Many thanks in advance.
 
You can use DCount to count the number of records that match a criteria. Combine the DCount with an if statement that opens FormB when the record does exist (count greater than 0) or FormC when the record doesnt (count = 0)
[tt]
If DCount("[MyField]","MyTableOrQuery","[Criteria]=[Criteria]")>0 Then
DoCmd.OpenForm "FormB"
Else
DoCmd.OpenForm "FormC"
End If
[/tt]

HTH Joe Miller
joe.miller@flotech.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top