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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open Form on matched record 1

Status
Not open for further replies.

handlebarry

Technical User
Dec 21, 2004
118
GB
Hi - trying to workout how to open a form if a criteria is matched. Using earlier strings I have come up with:

Dim stDocName As String
Dim strSQL As String
Dim strSQLWhere As String
Dim lngCount As Long
Dim strHelp As String
Dim crlf As String
stDocName = "frmContractDetails"
strHelp = "This Property has no contracts"

strSQL = "SELECT * FROM tblContractsToProperties"
strSQLWhere = ((tblContractsToProperties.GIS_Property_Code) = [Forms]![frmProperty]![txtGIS_Property_Code])
strSQL = strSQL & " WHERE " & strSQLWhere
lngCount = FindRecord(strSQL)

If lngCount = 0 Then Message = MsgBox(strHelp, vbExclamation)
Else
DoCmd.OpenForm stDocName


The code gets as far FindRecord - sub or function not defined

Can someone please advise as to whether this is the best method and if so how to define FindRecord

thanks
 
I'd rewrite the whole procedure using DCount. For example:

Code:
If DCount ("*", "tblContractsToProperties", "GIS_Property_Code='" & [Forms]![frmProperty]![txtGIS_Property_Code] & "'") > 0 Then
  DoCmd.OpenForm "frmContractDetails"
Else
  Msgbox "This property has no contracts", vbExclamation
End If

You won't need any of the variables either.

John

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top