473,395 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Hope someone can help me with this...trying to keep invalid or dupes on records

I have 2 fields that I have to make sure don't get screwed up.
(could be one it doesn't matter)
but what they want is no duplicates, warn the user
changing existing numbers is a no no. (of course they will have to
change errors so this is kinda WHAT ??)
the way it is set up is they put in an account number then a person id
number (which is text LOL)

ok if existing acount number then set it back to whatever and warn
them.

But I can't get all the checks to work at the same time, new record
can't equal old record in acount number or person id... BOTH are
unique.

so I keep fixing one way and another way doesn't work right.

are there any geniuses out there that can tell me what I need to
modify to catch existing value on entry as well as changing value to
existing values.

thanks big time for help I am just going in circles

Jerry

================================================== ==
so what I did was this on before update of the 2 fields...
trying acount number and it if passes going to person id then checking
and if it passes ok good record...If not setting back to whatever

Private Sub AcntNumber_BeforeUpdate(Cancel As Integer)
Cancel = ckContinue("AcntNumber")
End Sub

Private Sub PersonID_BeforeUpdate(Cancel As Integer)
Cancel = ckContinue("personid")
End Sub

================================================== ==

Public Function ckContinue(cname As String) As Boolean

Dim rst As Recordset
Dim str As String
Dim delim As String

If IsNull(Me.Controls(cname).Value) Then
MsgBox " You Must put in a valid AcntNumber to continue"
ActiveControl.Undo
DoCmd.RunCommand acCmdUndo
Else
str = Me.Controls(cname).Value
Set rst = CurrentDb.OpenRecordset(Me.RecordSource, dbOpenDynaset)
If rst.Fields(cname).Type = dbText Then
delim = """"
Else
delim = ""
End If

rst.FindFirst "[" & cname & "] = " & delim & str & delim

If Not rst.NoMatch Then
MsgBox "A record with AcntNumber = " & rst!AcntNumber & "
ID number = " & rst!idnum & " already exists"
ActiveControl.Undo
DoCmd.RunCommand acCmdUndo
Else
Exit Function
End If
rst.Close
End If
End Function
Jul 14 '06 #1
3 1493
Make a unique index or indexes, or a unique non-null index or indexes
as the case requires. Disallow zero length strings if you wish. Let
Access/Jet handle the rest, including messages etc.
Tell "they" that's the way it is.
Sleep soundly; all is under control.

Jul 14 '06 #2
sparks <js******@swbell.netwrote in
news:1o********************************@4ax.com:
I have 2 fields that I have to make sure don't get screwed up.
(could be one it doesn't matter)
but what they want is no duplicates, warn the user
changing existing numbers is a no no. (of course they will
have to change errors so this is kinda WHAT ??)
the way it is set up is they put in an account number then a
person id number (which is text LOL)

ok if existing acount number then set it back to whatever and
warn them.

But I can't get all the checks to work at the same time, new
record can't equal old record in acount number or person id...
BOTH are unique.
So I can have only one account, and that can't be a joint
account with my significant othre. If this is for a bank, tell
me which one, so I can avoid doing business there.
so I keep fixing one way and another way doesn't work right.
If the personID and accountID are both unique, one ID is
redundant.

Anyways, tackle the two problems individually, your code is much
more convoluted than it need be

In the Before_Update Event of the account number, simply do a

if NOT isnull(dlookup("accountID", _
"tableName", _
accountID = " & me.accountID & ")" then
cancel = true
msgbox "Duplicate Account Number Not Allowed"
end if

Use the same concept in the PersonID's BeforeUpdate event
>
are there any geniuses out there that can tell me what I need
to modify to catch existing value on entry as well as changing
value to existing values.

thanks big time for help I am just going in circles

Jerry
Good luck.

>
================================================== ==
so what I did was this on before update of the 2 fields...
trying acount number and it if passes going to person id then
checking and if it passes ok good record...If not setting back
to whatever

Private Sub AcntNumber_BeforeUpdate(Cancel As Integer)
Cancel = ckContinue("AcntNumber")
End Sub

Private Sub PersonID_BeforeUpdate(Cancel As Integer)
Cancel = ckContinue("personid")
End Sub

================================================== ==

Public Function ckContinue(cname As String) As Boolean

Dim rst As Recordset
Dim str As String
Dim delim As String

If IsNull(Me.Controls(cname).Value) Then
MsgBox " You Must put in a valid AcntNumber to continue"
ActiveControl.Undo
DoCmd.RunCommand acCmdUndo
Else
str = Me.Controls(cname).Value
Set rst = CurrentDb.OpenRecordset(Me.RecordSource,
dbOpenDynaset) If rst.Fields(cname).Type = dbText Then
delim = """"
Else
delim = ""
End If

rst.FindFirst "[" & cname & "] = " & delim & str & delim

If Not rst.NoMatch Then
MsgBox "A record with AcntNumber = " &
rst!AcntNumber & "
ID number = " & rst!idnum & " already exists"
ActiveControl.Undo
DoCmd.RunCommand acCmdUndo
Else
Exit Function
End If
rst.Close
End If
End Function


--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Jul 14 '06 #3
Thanks Bob I will give this a go.

At first it was an account No.
Then they came up with the Person ID
It made no since to me since they were the same person.
Just 2 different ways to identify them.
They said oh 2 different departments...one is assigning the account
number. then the other dept assigns them a person ID.
Like you said this is 2 numbers for the same person but that is what
they want.

I will check the act num and if its ok then move on to the person num.

the problem is with something like this

act num person num
1 1
2 18

new record they type in
3 1
on one I tell them that its used. ok yours works fine

now they go to existing record of 1 1 and type
2 as soon as they do I have to set it back to 1
this yours will do also...
man I have mentally walked thru this a hundred times it kinda makes
since..but like you...WHY 2 ROFL

oh well its friday so I can put up the machine gun and go get a beer
Jerry


On 14 Jul 2006 18:59:05 GMT, Bob Quintal <rq******@sPAmpatico.ca>
wrote:
>sparks <js******@swbell.netwrote in
news:1o********************************@4ax.com :
>I have 2 fields that I have to make sure don't get screwed up.
(could be one it doesn't matter)
but what they want is no duplicates, warn the user
changing existing numbers is a no no. (of course they will
have to change errors so this is kinda WHAT ??)
the way it is set up is they put in an account number then a
person id number (which is text LOL)

ok if existing acount number then set it back to whatever and
warn them.

But I can't get all the checks to work at the same time, new
record can't equal old record in acount number or person id...
BOTH are unique.
So I can have only one account, and that can't be a joint
account with my significant othre. If this is for a bank, tell
me which one, so I can avoid doing business there.
>so I keep fixing one way and another way doesn't work right.

If the personID and accountID are both unique, one ID is
redundant.

Anyways, tackle the two problems individually, your code is much
more convoluted than it need be

In the Before_Update Event of the account number, simply do a

if NOT isnull(dlookup("accountID", _
"tableName", _
accountID = " & me.accountID & ")" then
cancel = true
msgbox "Duplicate Account Number Not Allowed"
end if

Use the same concept in the PersonID's BeforeUpdate event
>>
are there any geniuses out there that can tell me what I need
to modify to catch existing value on entry as well as changing
value to existing values.

thanks big time for help I am just going in circles

Jerry

Good luck.

>>
================================================= ===
so what I did was this on before update of the 2 fields...
trying acount number and it if passes going to person id then
checking and if it passes ok good record...If not setting back
to whatever

Private Sub AcntNumber_BeforeUpdate(Cancel As Integer)
Cancel = ckContinue("AcntNumber")
End Sub

Private Sub PersonID_BeforeUpdate(Cancel As Integer)
Cancel = ckContinue("personid")
End Sub

================================================= ===

Public Function ckContinue(cname As String) As Boolean

Dim rst As Recordset
Dim str As String
Dim delim As String

If IsNull(Me.Controls(cname).Value) Then
MsgBox " You Must put in a valid AcntNumber to continue"
ActiveControl.Undo
DoCmd.RunCommand acCmdUndo
Else
str = Me.Controls(cname).Value
Set rst = CurrentDb.OpenRecordset(Me.RecordSource,
dbOpenDynaset) If rst.Fields(cname).Type = dbText Then
delim = """"
Else
delim = ""
End If

rst.FindFirst "[" & cname & "] = " & delim & str & delim

If Not rst.NoMatch Then
MsgBox "A record with AcntNumber = " &
rst!AcntNumber & "
ID number = " & rst!idnum & " already exists"
ActiveControl.Undo
DoCmd.RunCommand acCmdUndo
Else
Exit Function
End If
rst.Close
End If
End Function

--
Bob Quintal

PA is y I've altered my email address.
Jul 14 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Mahmood Ahmad | last post by:
Hello, I have written a program that reads three types of records, validates them acording to certain requirements and writes the valid records into a binary file. The invalid records are...
6
by: firewire888 | last post by:
I tried a bunch of sql queries, but can't get this sql correct. Any help would be appreciated. Thanks. I have a two field table, key1, key2 key1 field can have dupes key2 field is...
7
by: Amy | last post by:
I'm trying to add an autoincrementing id to a table based on an existing field Name, but Name has duplicated records. How can I do that in ACCESS? Thanks. Amy
20
by: Jack Schitt | last post by:
I thought I was starting to get a handle on Access, until I tried doing something useful...now I'm stuck. I have a DB with two tables - to keep it simple I'll say that one is an Employee File...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.