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

BeforeUpDate, access 97

Status
Not open for further replies.

Heita

Instructor
Jun 21, 2001
6
SE
Hi!

I have Form where the user can tipe in information which is saved in a table by pressing a button. I want a msgbox appear if the keyfield has the same value as a field in the table (duplicate value) when the "Save" button is pressed. Can the BeforeUpDate be used in some way?

I know access has en error handler for duplicate fields but it´s in english and doesn´t appear when I want too.

Thanx
 
Hi, Heita!

There is your needed codes:

Private Sub CheckField_BeforeUpdate(Cancel As Integer)
Dim strSQL As String
Dim rst As Recordset

strSQL = "SELECT Test.CheckField FROM Test "
strSQL = strSQL & "WHERE Test.CheckField=" & Me.CheckField & ";"
Set rst = CurrentDb.OpenRecordset(strSQL)
If Not rst.EOF Then
MsgBox "You already have ....", vbInformation, "Duplicate value ..."
Me.CheckField.Undo
Cancel = True
End If
rst.Close
Set rst = Nothing
End Sub

Aivars

 
Hi!

thanx but I just get still the window saying " you can´t go to the specified record, u may be at the end of the record set". doh.


And i´m sorry but I do u mean
strSQL="SELECT textbox Or fieldname in table/Orfrom.checkfield FROM Table or Form?

´thanx again



 
Hi, Heita, again!

There are more simple codes:

Private Sub MyTextBox_BeforeUpdate(Cancel As Integer)
if not isnull(dlookup("MyField","MyTable","MyField='" & me.MyTextBox & "'")) then
MsgBox "You already have ....", vbInformation, "Duplicate value ..."
Me.MyTextBox.Undo
Cancel = True
End If
rst.Close
Set rst = Nothing
End Sub

Aivars
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top