DLookup Function returns True or False (1 Viewer)

Rx_

Nothing In Moderation
Local time
Yesterday, 18:02
Joined
Oct 22, 2009
Messages
2,803
Code:
' Number EPA - Check to see if a number exist based on a key value
' If no associated record exist OR  if 1 or many records exist
Function NEPA_Exist(ID_Well As Long) As Boolean
      'DLookup("FieldName" , "TableName" , "Criteria = n")
      '  The ID_Well from a listbox event calls this function - the function returns true of false
     ' Use this with other code to inform the user if a record exist or not
      Dim ReturnValue         As Variant       ' null or a number
      Dim MyFieldName         As String
      Dim MyTableName         As String
10    MyFieldName = "ID_NEPA_Wells"           ' name of field in table name
20    MyTableName = "NEPA_Wells"              ' name of table to lookup the value for match
30    On Error Resume Next
40    ReturnValue = DLookup(MyFieldName, MyTableName, "[ID_Wells] =" & ID_Well)
50    If Not IsNull(ReturnValue) Then
60        NEPA_Exist = True
70    Else
80         NEPA_Exist = False
90    End If
End Function
 

Users who are viewing this thread

Top Bottom