Check a table to see if record already exists

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How can I check a table to see if a record already exists? In this case
checking to see if a network ID (jdb1) has already been used before I create
a new user with that network ID? I have a variable equal to the proposed
login (jdb1) and I want to find out if there is already a record in the Old
Users table that used the proposed login.
 
I Understand that you want to check using VBA, so when you use dlookup if the
record doesn't exist it will return null

if isnull("MyField","MyTable","MyField = " & Parameter ) then
continue
else
msgbox "ëxist"
endif
 
I have a small function in a module to return true if a table or query exists

Function ObjectExists(strObject As String, lngtype As String) As Boolean
Dim obj As AccessObject
Dim dbs As Object
Dim objType As Object
Set dbs = Application.CurrentData
ObjectExists = False


Select Case lngtype
Case acTable
Set objType = dbs.AllTables
Case acQuery
Set objType = dbs.AllQueries

End Select

' Search for existence of AccessObject objects in appropriate collection.
For Each obj In objType
If obj.Name = strObject Then
ObjectExists = True
Exit For
End If
Next obj

End Function
 
Back
Top