473,624 Members | 2,240 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_Befo reUpdate(Cancel As Integer)
Cancel = ckContinue("Acn tNumber")
End Sub

Private Sub PersonID_Before Update(Cancel As Integer)
Cancel = ckContinue("per sonid")
End Sub

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

Public Function ckContinue(cnam e As String) As Boolean

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

If IsNull(Me.Contr ols(cname).Valu e) Then
MsgBox " You Must put in a valid AcntNumber to continue"
ActiveControl.U ndo
DoCmd.RunComman d acCmdUndo
Else
str = Me.Controls(cna me).Value
Set rst = CurrentDb.OpenR ecordset(Me.Rec ordSource, dbOpenDynaset)
If rst.Fields(cnam e).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.U ndo
DoCmd.RunComman d acCmdUndo
Else
Exit Function
End If
rst.Close
End If
End Function
Jul 14 '06 #1
3 1502
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******@swbel l.netwrote in
news:1o******** *************** *********@4ax.c om:
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_Befo reUpdate(Cancel As Integer)
Cancel = ckContinue("Acn tNumber")
End Sub

Private Sub PersonID_Before Update(Cancel As Integer)
Cancel = ckContinue("per sonid")
End Sub

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

Public Function ckContinue(cnam e As String) As Boolean

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

If IsNull(Me.Contr ols(cname).Valu e) Then
MsgBox " You Must put in a valid AcntNumber to continue"
ActiveControl.U ndo
DoCmd.RunComman d acCmdUndo
Else
str = Me.Controls(cna me).Value
Set rst = CurrentDb.OpenR ecordset(Me.Rec ordSource,
dbOpenDynaset) If rst.Fields(cnam e).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.U ndo
DoCmd.RunComman d 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...o ne 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******@sPAmp atico.ca>
wrote:
>sparks <js******@swbel l.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_Befo reUpdate(Cancel As Integer)
Cancel = ckContinue("Acn tNumber")
End Sub

Private Sub PersonID_Before Update(Cancel As Integer)
Cancel = ckContinue("per sonid")
End Sub

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

Public Function ckContinue(cnam e As String) As Boolean

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

If IsNull(Me.Contr ols(cname).Valu e) Then
MsgBox " You Must put in a valid AcntNumber to continue"
ActiveControl.U ndo
DoCmd.RunComman d acCmdUndo
Else
str = Me.Controls(cna me).Value
Set rst = CurrentDb.OpenR ecordset(Me.Rec ordSource,
dbOpenDynaset) If rst.Fields(cnam e).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.U ndo
DoCmd.RunComman d 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
2970
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 supposed to be reported on the printer but I have commented those pieces of code and have got those records printed on the screen. I am using Microsoft Visual C++ 6.0 on Microsoft XP (Home) platform. I am facing some problems in getting desire...
6
1234
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 unique
7
3278
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
2355
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 (Employees), and the other is an Address File (Addresses) linked by SSN. I've set Addresses as a Lookup Table - If the user starts typing in the SSN it should pull up the Employees records. I'm getting stuck in the Data Entry form. When I type in...
0
8177
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8681
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8629
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8488
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6112
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4183
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2611
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1793
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1488
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.