Ok, we just have to check one field, not multiple fields? See if this is
enough assistance or if you need more detailed code. Assumptions for example:
This would be in the AfterUpdate event for the text box control on the form
named txt_EnteredName. The table is tbl_DataTable and it has a field in it
named fld_Name.
Prepare by declaring some variables to reference the database and table:
Dim LocalDB as Database
Dim LocalRST as Recordset
This would be on a single line beginning with If and ending with Then:
If Nz(DCount("[fld_Name]", "tbl_DataTable", "[fld_Name] LIKE " &
Me.txt_EnteredName)) = 0 Then
'add record because we found a matching name
Set LocalDB = CurrentDB
Set LocalRST = LocalDB.OpenRecordset ("tbl_DataTable")
With LocalRST
.AddNew
![fld_Name] = Me.txt_EnteredName
![anotherField] = Me.AnotherTextBox
![Field3] = Me.ThirdTextBox
.Update
.Close
End With
Set LocalRST=Nothing
LocalDB.Close
Set LocalDB = Nothing ' reclaim all resources
Else
'do nothing, no matching name found
'you could put up a "name not found" message
' or if you really don't want to do anything, then
' you don't even need this Else section.
End If
Hope this helps. P.S. not MVP Access - but I struggle along. Someone else
may offer different/better code.
If you wanted, you could even test within the .AddNew ... .Update section to
see if the various text boxes contain anything or not, and if not, don't even
mess with trying to update a field that is not a required field and does
accept Nulls. Something like:
If Me.AnotherTextBox <> "" Then
'only does this when AnotherTextBox on form is NOT empty.
!AnotherField = Me.AnotherTextBox
End If