check to see if a record already exists

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

Guest

I am trying to check to see if this record already exists in a table. This
function (doesMemberExist) keeps returing null. I think I know the problem
but I don't really know how to fix it partially because I don't understand
how this function works. The table's primary key is made up of the
combination of 2 fields. The form the parent contains the first field in the
key and its subform contains the second.

membersCheck = "Select * FROM [myTable]"
If Not DoesMemberExist(recordCheck) Then
.....
End If

Public Function DoesMemberExist(sSource) As Boolean

'Checks to see if the members that are contained in the 'sSource'
'are inserted or if they are null
Dim db As DAO.Database
Dim rst As DAO.Recordset
Set db = CurrentDb
Set rst = db.OpenRecordset(sSource)

DoesMemberExist = Not rst.EOF

rst.Close
db.Close
Set rst = Nothing
Set db = Nothing
Exit Function

End Function

How can I change this function to allow it to work and if thats not the
problem any suggestions?
 
1. You "membersCheck" SQL String will select *all* Records in the [myTable]
which is, clearly, not what you need.

2. You didn't even pass the incorrect SQL in "membersCheck" to the
function. Pou pass "recordCheck" which is not defined in the code you
posted.

3. It is probably much easier to use DCount() or DLookUp() function.

Check Access VB Help on the above functions.

HTH
Van T. Dinh
MVP (Access)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top