I have one text box, and one command, text box for inputting 9 digitS number,,the command to check if the inputs are duplicated, if duplicated, then give error message, my code: -
Private Sub Command42_Click()
-
On Error GoTo Err_Command42_Click
-
-
Dim strSQL As String
-
Dim strsql2 As String
-
Dim db As Database
-
Dim strMsg As String
-
-
Dim rs As DAO.Recordset
-
-
Dim stDocName As String
-
Dim stLinkCriteria As String
-
-
Set db = CurrentDb()
-
strSQL = "SELECT * from A "
-
strsql2 = " WHERE A_NUMBER = '" & Me.txtSSN & "' "
-
Set rs = db.OpenRecordset(strSQL + strsql2, dbOpenSnapshot)
-
-
If rs.EOF = False Then
-
-
MsgBox "Person with the same A number already exists in the DB", vbCritical
-
-
Else
-
-
strSQL = "INSERT INTO A (A_NUMBER) VALUES ('" & Me.txtSSN & "')"
-
db.Execute strSQL
-
Me.A_LIST_SUBFORM_QRY_subform.Requery
-
-
stDocName = "LOP"
-
stLinkCriteria = "[A_NUMBER]=" & "'" & Me.txtSSN & "'"
-
DoCmd.OpenForm stDocName, , , stLinkCriteria
-
-
-
End If
-
-
Set rs = Nothing
-
Set db = Nothing
-
-
-
Exit_Command42_Click:
-
Exit Sub
-
-
Err_Command42_Click:
-
MsgBox Err.Description
-
Resume Exit_Command42_Click
-
-
End Sub
-
-
this is a working code, but right now I want to bypass the '000000000', that means I only allow to be duplicated only if txtSSN value is '000000000' , anyone can help on this? Many thanks~~
11 1417
Change Line 19 to -
If rs.EOF = False or rs!A_NUMBER = 000000000 Then
-
Change Line 19 to -
If rs.EOF = False or rs!A_NUMBER = 000000000 Then
-
Thank you, I will try tomorrow.
Thank you, I will try tomorrow.
Oops, I looked at it again and that won't work. It should have been -
If rs.EOF = False and rs!A_NUMBER <> 000000000 Then
-
Oops, I looked at it again and that won't work. It should have been -
If rs.EOF = False and rs!A_NUMBER <> 000000000 Then
-
The logic is not right, it can't let 000000000 repeatly input, anybody else can help on this , many thanks!
The logic is not right, it can't let 000000000 repeatly input, anybody else can help on this , many thanks!
And when I tried to modify the code as this: -
strsql2 = " WHERE A_NUMBER = '" & Me.txtSSN & "' And A_NUMBER <> '000000000'"
-
-
when input the 000000000 in text field again and click the command to add new record, the 00000000 didn't be inserted again as duplicates, but went into the old a_number is 000000000 old record.
The logic is not right, it can't let 000000000 repeatly input, anybody else can help on this , many thanks!
By chance is the A_Number field set to no duplicates in your table?
Yes, the a_number is not allow duplicate, but it is a possible that someone who without a_number, then have to give 000-000-000 to him/her, so there is possibility more than one person without a_number, that's why it only allow 000-000-000 duplicated.
anyone else can help me?
Yes, the a_number is not allow duplicate, but it is a possible that someone who without a_number, then have to give 000-000-000 to him/her, so there is possibility more than one person without a_number, that's why it only allow 000-000-000 duplicated.
anyone else can help me?
You've answered your own question then, if your field won't allow duplicates then you can't put a duplicate number in no matter how you try to get arround it.
JayJayPlane, we are all volunteers here - so please understand that if your database is set not to allow duplicates, then as Don said in his last post you can't work round this (nor should you!) no matter how hard you try.
Please don't waste the efforts of the volunteers on this site by overlooking the most obvious of constraints which you already knew of when you posted. Databases behave very systematically, and cannot ignore 'no duplicates' rules...
Please understand also that asking for others to assist whilst ignoring the guidance you have already been given is at best unhelpful and at worst rude to our volunteer posters.
MODERATOR
JayJayPlane, we are all volunteers here - so please understand that if your database is set not to allow duplicates, then as Don said in his last post you can't work round this (nor should you!) no matter how hard you try.
Please don't waste the efforts of the volunteers on this site by overlooking the most obvious of constraints which you already knew of when you posted. Databases behave very systematically, and cannot ignore 'no duplicates' rules...
Please understand also that asking for others to assist whilst ignoring the guidance you have already been given is at best unhelpful and at worst rude to our volunteer posters.
MODERATOR
Hi Forum leader,
Sorry about that, I have no any intention to be rude and waste anyone time.
My database is not too restrict, just based on the reqirement, I didn't set a_number is PK, although it should be, but I just don't want it duplicated, except for those without a_number, can repeatly give the 000-000-000.
Anyway, thanks everyone here help me, bow~~bye~~
NeoPa 32,556
Recognized Expert Moderator MVP
JayJay,
Although this may seem confusing to you, the answer you need is in this thread already.
Make sure the field is set up so that duplicates ARE allowed.
Use Don's amendment to your code to ensure only all 0s can be duplicated.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: jason |
last post by:
Is there a way - possibly a disconnected rs? - to update the contents of an
existing pulldown on a page without having to re-submit the page for the
user to see the pulldown populated with an...
|
by: Joerg Toellner |
last post by:
Dear Group,
i have a self written c++-class that is used in many projects from many
programmers.
The functionality of this class requests, for some reasons, that any
instance (object) of this...
|
by: TGOS |
last post by:
I was thinking about it for a while, a mutex written in C and without
disabling any interrupts. Is it possible?
typdef struct mutex {
unsigned int owner1;
unsigend int owner2;
} *mutex;
...
|
by: trint |
last post by:
add them into one PrintDocument:
PrintDocument pd1 = new PrintDocument();
PrintDocument pd2 = new PrintDocument();
PrintDocument pdCombined = new PrintDocument();
pdCombined = pd1 + pd2;...
|
by: noobcprogrammer |
last post by:
#include "IndexADT.h"
int IndexInit(IndexADT* word)
{
word->head = NULL;
word->wordCount = 0;
return 1;
}
int IndexCreate(IndexADT* wordList,char* argv)
|
by: Licheng Fang |
last post by:
Basically, the problem is this:
'do'
Python's NFA regexp engine trys only the first option, and happily
rests on that. There's another example:
'oneself'
The Python regular expression...
|
by: mosesdinakaran |
last post by:
Hi All,
I need a small clarification in submitting the forms, Ur
suggestions please.
In a page I have two form and also two submit butons.
(ie)
|
by: highab |
last post by:
Hello,
I want to send a parameter (string) to an external js file.
I found something very similar to what I wanted with you but it doesn't answer my question, so here goes:
I call my...
|
by: KevinADC |
last post by:
Purpose
The purpose of this article is to discuss the difference between characters inside a character class and outside a character class and some special characters inside a character class....
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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,...
|
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...
|
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...
|
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: 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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
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 ...
| |