dbTalk Databases Forums  

FIELD VALIDATION

comp.database.ms-access comp.database.ms-access


Discuss FIELD VALIDATION in the comp.database.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
sp_1000
 
Posts: n/a

Default FIELD VALIDATION - 04-18-2004 , 05:40 PM






Access MDB connected to SQL Server. Working with Inventory form.

Need to check a value of BookID (Text) field to prevent duplicates in
Books table.

The Inventory form already has several lines of code checking for
empty fields: BookID, Author, etc. when Ok button pushed.

Need to make sure that the new code (BookID field validation) is
bypassed when users modify old records. Otherwise users will be
getting ("BookID already exists") error any time they try to modify
any field of the Inventory form.

Trying:

-------------------------------------------------------------------
Private Sub Form_BeforeInsert(Cancel As Integer)
If (Not IsNull(DLookup("[BookID]", "Books", "[BookID] ='" & Me!BookID
& "'"))) Then
MsgBox "BookID already exists", vbCritical, "Error"
DoCmd.GoToControl "BookID"
DoCmd.CancelEvent
End If
End Sub
-------------------------------------------------------------------

And it doesn't work.

Any help would be appreciated.
Please be as specific as possible.

Thanks in advance for your prompt respond.

Reply With Quote
  #2  
Old   
Ira Solomon
 
Posts: n/a

Default Re: FIELD VALIDATION - 04-20-2004 , 08:44 PM






Put your check in the afterupdate event for the field. Also, I would
use Dcount.
On 18 Apr 2004 15:40:12 -0700, lovevsmatrix (AT) yahoo (DOT) com (sp_1000) wrote:

Quote:
Access MDB connected to SQL Server. Working with Inventory form.

Need to check a value of BookID (Text) field to prevent duplicates in
Books table.

The Inventory form already has several lines of code checking for
empty fields: BookID, Author, etc. when Ok button pushed.

Need to make sure that the new code (BookID field validation) is
bypassed when users modify old records. Otherwise users will be
getting ("BookID already exists") error any time they try to modify
any field of the Inventory form.

Trying:

-------------------------------------------------------------------
Private Sub Form_BeforeInsert(Cancel As Integer)
If (Not IsNull(DLookup("[BookID]", "Books", "[BookID] ='" & Me!BookID
& "'"))) Then
MsgBox "BookID already exists", vbCritical, "Error"
DoCmd.GoToControl "BookID"
DoCmd.CancelEvent
End If
End Sub
-------------------------------------------------------------------

And it doesn't work.

Any help would be appreciated.
Please be as specific as possible.

Thanks in advance for your prompt respond.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.