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

I would like to query to see if a record already exists

Status
Not open for further replies.

RickyC1

Programmer
Apr 11, 2002
8
US
I have a screen which saves the content of the screen to a table. I would like to put in some functionality before the record is appended to see if it already exists.

Any ideas?
 
private sub form_BeforeUpdate(cancel as integer)
dim rst as recordset

set rst=me.recordsetclone
'Use the valid markers for different field types e.g. for date #
'Find the record with entered data

rst.findfirst="MyDateField=#" & me.MyCompDate & "#"
if not rst.nomatch then
'Record is found
msgbox "The record already is saved..."
'Cancel update operation
cancel=true
end if
'Close recordsets
rst.close
set rst=nothing
end sub


Also you can check for existing of data before any control's updating. In this case you may put code above into sub program e.g.
private sub MyDateField_BeforeUpdate(cancel as integer)

Aivars
 
Check out Access help for the DLookup function.
Code:
Dim strX As Variant
If Not (IsNull(strX = DLookup("[empl_num]", "tblMaster", "[empl_num] = '" & Forms!frmEmplMasterMain!txtEmplNum & "'"))) Then
......
......
End If
[code]
This DLookup statement will be true if the employee number already exists.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top