If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Check for duplicates on loosefocus
Hi,
I'm trying to build a form that has a non automatic number as primary key. However, I would like to set the message of "record cannot be saved" to activate right after you enter that field, and not needing to wait until you move to the next record. Which is the best way to do that? -- M |
#2
|
|||
|
|||
Check for duplicates on loosefocus
Use the AfterUpdate event of the control to DLookup() the value in the
table, and see if it already exists. This example assumes a numeric primary key named ID, in Table1: Private Sub ID_AfterUpdate() Dim strWhere As String With Me.ID If IsNull(.Value) Or (.Value = .OldValue) Then 'do nothing Else If Not IsNull(DLookup("ID", "Table1","ID = " & .Value)) Then MsgBox "Duplicate ID." End If End If End With End Sub For further help with DLookup() see: Getting a value from a table: DLookup() at: http://allenbrowne.com/casu-07.html -- Allen Browne - Microsoft MVP. Perth, Western Australia. Tips for Access users - http://allenbrowne.com/tips.html Reply to group, rather than allenbrowne at mvps dot org. "Marte Cabello" wrote in message ... Hi, I'm trying to build a form that has a non automatic number as primary key. However, I would like to set the message of "record cannot be saved" to activate right after you enter that field, and not needing to wait until you move to the next record. Which is the best way to do that? -- M |
#3
|
|||
|
|||
Check for duplicates on loosefocus
Use DLookup() or DCount() in the BeforeUpdate event of the control. If you have
a duplicate you can Cancel the update and hold the focus in the control. On Fri, 9 Dec 2005 07:10:02 -0800, "Marte Cabello" wrote: Hi, I'm trying to build a form that has a non automatic number as primary key. However, I would like to set the message of "record cannot be saved" to activate right after you enter that field, and not needing to wait until you move to the next record. Which is the best way to do that? _______________________________________________ hth - RuralGuy (RG for short) Please post to the NewsGroup so all may benefit. |
#4
|
|||
|
|||
Check for duplicates on loosefocus
Great! It works.
Thanks. -- M "Allen Browne" wrote: Use the AfterUpdate event of the control to DLookup() the value in the table, and see if it already exists. This example assumes a numeric primary key named ID, in Table1: Private Sub ID_AfterUpdate() Dim strWhere As String With Me.ID If IsNull(.Value) Or (.Value = .OldValue) Then 'do nothing Else If Not IsNull(DLookup("ID", "Table1","ID = " & .Value)) Then MsgBox "Duplicate ID." End If End If End With End Sub For further help with DLookup() see: Getting a value from a table: DLookup() at: http://allenbrowne.com/casu-07.html -- Allen Browne - Microsoft MVP. Perth, Western Australia. Tips for Access users - http://allenbrowne.com/tips.html Reply to group, rather than allenbrowne at mvps dot org. "Marte Cabello" wrote in message ... Hi, I'm trying to build a form that has a non automatic number as primary key. However, I would like to set the message of "record cannot be saved" to activate right after you enter that field, and not needing to wait until you move to the next record. Which is the best way to do that? -- M |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Can I check multiple check boxes with one click? | tobesus | Using Forms | 1 | August 12th, 2005 01:38 AM |
One Check box to check all check boxes | Mark Senibaldi | Using Forms | 2 | April 12th, 2005 04:27 PM |
File Check Out System | Emily | Database Design | 3 | September 29th, 2004 05:25 PM |
Spelling & Grammar Check -- Marked Text Skip | Larry Coles | General Discussion | 1 | September 6th, 2004 01:10 AM |
Check box used in Macro | Kurt | Using Forms | 2 | September 1st, 2004 03:22 PM |