473,466 Members | 1,343 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Is It possible to bybass the special situation

26 New Member
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:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command42_Click()
  2. On Error GoTo Err_Command42_Click
  3.  
  4.     Dim strSQL As String
  5.     Dim strsql2 As String
  6.     Dim db As Database
  7.     Dim strMsg As String
  8.  
  9.     Dim rs As DAO.Recordset
  10.  
  11.     Dim stDocName As String
  12.     Dim stLinkCriteria As String
  13.  
  14.     Set db = CurrentDb()
  15.     strSQL = "SELECT * from A "
  16.     strsql2 = " WHERE A_NUMBER  = '" & Me.txtSSN & "' "
  17.     Set rs = db.OpenRecordset(strSQL + strsql2, dbOpenSnapshot)
  18.  
  19.     If rs.EOF = False Then
  20.  
  21.         MsgBox "Person with the same A number already exists in the DB", vbCritical
  22.  
  23.     Else
  24.  
  25.         strSQL = "INSERT INTO A  (A_NUMBER) VALUES ('" & Me.txtSSN & "')"
  26.         db.Execute strSQL
  27.         Me.A_LIST_SUBFORM_QRY_subform.Requery
  28.  
  29.         stDocName = "LOP"
  30.         stLinkCriteria = "[A_NUMBER]=" & "'" & Me.txtSSN & "'"
  31.         DoCmd.OpenForm stDocName, , , stLinkCriteria
  32.  
  33.  
  34.     End If
  35.  
  36.       Set rs = Nothing
  37.       Set db = Nothing
  38.  
  39.  
  40. Exit_Command42_Click:
  41.     Exit Sub
  42.  
  43. Err_Command42_Click:
  44.     MsgBox Err.Description
  45.     Resume Exit_Command42_Click
  46.  
  47. End Sub
  48.  
  49.  
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~~
Oct 20 '08 #1
11 1417
DonRayner
489 Recognized Expert Contributor
Change Line 19 to

Expand|Select|Wrap|Line Numbers
  1.  If rs.EOF = False or rs!A_NUMBER = 000000000 Then
  2.  
Oct 20 '08 #2
jayjayplane
26 New Member
Change Line 19 to

Expand|Select|Wrap|Line Numbers
  1.  If rs.EOF = False or rs!A_NUMBER = 000000000 Then
  2.  


Thank you, I will try tomorrow.
Oct 22 '08 #3
DonRayner
489 Recognized Expert Contributor
Thank you, I will try tomorrow.
Oops, I looked at it again and that won't work. It should have been

Expand|Select|Wrap|Line Numbers
  1.  If rs.EOF = False and rs!A_NUMBER <> 000000000 Then
  2.  
Oct 22 '08 #4
jayjayplane
26 New Member
Oops, I looked at it again and that won't work. It should have been

Expand|Select|Wrap|Line Numbers
  1.  If rs.EOF = False and rs!A_NUMBER <> 000000000 Then
  2.  

The logic is not right, it can't let 000000000 repeatly input, anybody else can help on this , many thanks!
Oct 22 '08 #5
jayjayplane
26 New Member
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:

Expand|Select|Wrap|Line Numbers
  1. strsql2 = " WHERE A_NUMBER  = '" & Me.txtSSN & "' And A_NUMBER <> '000000000'"
  2.  
  3.  
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.
Oct 22 '08 #6
DonRayner
489 Recognized Expert Contributor
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?
Oct 22 '08 #7
jayjayplane
26 New Member
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?
Oct 23 '08 #8
DonRayner
489 Recognized Expert Contributor
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.
Oct 23 '08 #9
Stewart Ross
2,545 Recognized Expert Moderator Specialist
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
Oct 23 '08 #10
jayjayplane
26 New Member
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~~
Oct 23 '08 #11
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.
Oct 27 '08 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

7
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...
3
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...
4
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; ...
24
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;...
0
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)
32
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...
23
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)
3
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...
3
KevinADC
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....
1
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...
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
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...
1
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...
0
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...
0
agi2029
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,...
0
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...
0
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 ...

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.