A Microsoft Office (Excel, Word) forum. OfficeFrustration

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.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Check for duplicates on loosefocus



 
 
Thread Tools Display Modes
  #1  
Old December 9th, 2005, 03:10 PM posted to microsoft.public.access.forms
external usenet poster
 
Posts: n/a
Default 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  
Old December 9th, 2005, 03:24 PM posted to microsoft.public.access.forms
external usenet poster
 
Posts: n/a
Default 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  
Old December 9th, 2005, 03:33 PM posted to microsoft.public.access.forms
external usenet poster
 
Posts: n/a
Default 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  
Old December 9th, 2005, 03:45 PM posted to microsoft.public.access.forms
external usenet poster
 
Posts: n/a
Default 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

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 Off
HTML code is Off
Forum Jump

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


All times are GMT +1. The time now is 01:21 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.