One Number not repeated

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello

Is there is a way to allow only one number from being repeated when entering
data in a form

Example: Field A can be :1 or 2 or 3...., but 1 may not be repeated ,all
other numbers can be.
 
If you could do with not allowing 1 at all, in the table design you could
set the field validation rule to >1. Or set the field as the Primary Key and
it can never be duplicated.

Otherwise you would problaby have to do that in code. Say Before Update

Private sub textbox_beforeupdate
if me.textbox = 1 then
dim i as integer
i = dcount("[Field1]","TableName","[Field1]=1")
if i > 1 then
msgbox "No No No, must be 2 or higher.",vbCritical,"WARNING!"
docmd.cancelevent
end if
end if
end sub

Very sloppy air code but hopefully you will get the idea of what I mean.

Tony V
 
Thank you the code worked fine
--
Bassel


Tony Vrolyk said:
If you could do with not allowing 1 at all, in the table design you could
set the field validation rule to >1. Or set the field as the Primary Key and
it can never be duplicated.

Otherwise you would problaby have to do that in code. Say Before Update

Private sub textbox_beforeupdate
if me.textbox = 1 then
dim i as integer
i = dcount("[Field1]","TableName","[Field1]=1")
if i > 1 then
msgbox "No No No, must be 2 or higher.",vbCritical,"WARNING!"
docmd.cancelevent
end if
end if
end sub

Very sloppy air code but hopefully you will get the idea of what I mean.

Tony V


Bassel said:
Hello

Is there is a way to allow only one number from being repeated when
entering
data in a form

Example: Field A can be :1 or 2 or 3...., but 1 may not be repeated ,all
other numbers can be.
 
Back
Top