Hi Friends,
I have a table called Beneficiary where [Solar Lantern No] is the primary key. The user enter the [Solar Lantern No] number. Since the user enters the [SLNO], there is always a possibility that a duplicate value is entered. After entering the data, when the user saves the record, it should check whether the particular SLNo is already entered or not. if yes, then it should display a message box, else record saved.
By default there is a system generated message box.
looking fwd to hear from one of you.
Thanks
SAjit
7 1178
I think I am missing something here. If it is the PK then duplicates are not alowed and you will therfore not be able to save it when you try and a Access message will popup anyways. You do not have to do any checking for duplicate.
You may want (and I would) just create an ON ERROR event to trap the error and display your own message.
cheers,
Hi Friends,
I have a table called Beneficiary where [Solar Lantern No] is the primary key. The user enter the [Solar Lantern No] number. Since the user enters the [SLNO], there is always a possibility that a duplicate value is entered. After entering the data, when the user saves the record, it should check whether the particular SLNo is already entered or not. if yes, then it should display a message box, else record saved.
By default there is a system generated message box.
looking fwd to hear from one of you.
Thanks
SAjit
Thanks mshmyob,
Would be great if you could help me in writing this On ERROR Event..
Thanks
Sajit
I think I am missing something here. If it is the PK then duplicates are not alowed and you will therfore not be able to save it when you try and a Access message will popup anyways. You do not have to do any checking for duplicate.
You may want (and I would) just create an ON ERROR event to trap the error and display your own message.
cheers,
ON ERROR events are pretty straight forward.
In your form in the On Error event you might put some code that looks like this: -
'If an error occurs because of missing data in a required field
-
'display our own custom error message
-
-
' Display error information.
-
errCase = DataErr
-
-
Select Case errCase
-
Case 3314 ' missing required field value
-
LResponse = MsgBox("SSN required", vbOKOnly, errCase)
-
Response = acDataErrContinue
-
Case 0
-
'do nothing all is well
-
Case 3401
-
LResponse = MsgBox("SSN required", vbOKOnly, errCase)
-
Response = acDataErrContinue
-
Case 3058 ' index key blank
-
LResponse = MsgBox("SSN required", vbOKOnly, errCase)
-
Response = acDataErrContinue
-
Case 3022 ' duplicate index key
-
LResponse = MsgBox("SSN already exists.", vbOKOnly, errCase)
-
Response = acDataErrContinue
-
Case Else
-
MsgBox "Error number " & Err.Number & ": " & Err.Description
-
Response = acdatadisplay
-
End Select
-
Any erros you haven't trapped in any code will 'jump' down to here. For instance in your case if a person puts in an existing SSN into the PK the CASE 3022 will be triggered (error # 3022 is duplicate PK) and it will indicate that in a nice error message.
Notice error #3314 and 3401 will display the same message because some error numbers get triggered depending on how your design is.
Obviously you can build on this.
This is only one way. You could also create private onerror trapping. This way works quite nice for errors you don't think of ahead of time.
cheers,
Thanks mshmyob,
Would be great if you could help me in writing this On ERROR Event..
Thanks
Sajit
- thanks mshmyob,
-
-
this works.
-
-
I was just thinking if there is a way, the moment the user enters the SSN or solar Lantern no and moves for the next entry, the system should check whether that particular SSN or Solar Lantern no is there in the table or not. if yes, it should prompt a msgbox and the focus should shift back to the SSN textbox.
-
-
would be great if you can help me in coding this also.
-
Thanks
-
Sajit
ON ERROR events are pretty straight forward.
In your form in the On Error event you might put some code that looks like this: -
'If an error occurs because of missing data in a required field
-
'display our own custom error message
-
-
' Display error information.
-
errCase = DataErr
-
-
Select Case errCase
-
Case 3314 ' missing required field value
-
LResponse = MsgBox("SSN required", vbOKOnly, errCase)
-
Response = acDataErrContinue
-
Case 0
-
'do nothing all is well
-
Case 3401
-
LResponse = MsgBox("SSN required", vbOKOnly, errCase)
-
Response = acDataErrContinue
-
Case 3058 ' index key blank
-
LResponse = MsgBox("SSN required", vbOKOnly, errCase)
-
Response = acDataErrContinue
-
Case 3022 ' duplicate index key
-
LResponse = MsgBox("SSN already exists.", vbOKOnly, errCase)
-
Response = acDataErrContinue
-
Case Else
-
MsgBox "Error number " & Err.Number & ": " & Err.Description
-
Response = acdatadisplay
-
End Select
-
Any erros you haven't trapped in any code will 'jump' down to here. For instance in your case if a person puts in an existing SSN into the PK the CASE 3022 will be triggered (error # 3022 is duplicate PK) and it will indicate that in a nice error message.
Notice error #3314 and 3401 will display the same message because some error numbers get triggered depending on how your design is.
Obviously you can build on this.
This is only one way. You could also create private onerror trapping. This way works quite nice for errors you don't think of ahead of time.
cheers,
Yep you can do that also.
Put the following code in the 'After Update' event of the text box you want to check. -
' this will receive a TRUE or FALSE depending if the entry is found
-
Dim vCheckEntry As Variant
-
-
' use DLOOKUP method to look for your SSN
-
vCheckEntry = DLookup("[SSN_ID]", "tblSSN", "[SSN_ID] = '" & Me.txtSSN & "'")
-
If vCheckEntry = True Then
-
MsgBox ("SSN already exists. Please change it.")
-
Me.txtSSN.SetFocus
-
Else
-
' everyhting OK - do nothing
-
End If
-
By the way don't put your message text in '[code]' brackets. It is hard to read.
cheers, - thanks mshmyob,
-
-
this works.
-
-
I was just thinking if there is a way, the moment the user enters the SSN or solar Lantern no and moves for the next entry, the system should check whether that particular SSN or Solar Lantern no is there in the table or not. if yes, it should prompt a msgbox and the focus should shift back to the SSN textbox.
-
-
would be great if you can help me in coding this also.
-
Thanks
-
Sajit
Thank you...
it works... the only change which i need to do was to change the variable type from Variant to Boolean.
Thanks once again
Sajit
Yep you can do that also.
Put the following code in the 'After Update' event of the text box you want to check. -
' this will receive a TRUE or FALSE depending if the entry is found
-
Dim vCheckEntry As Variant
-
-
' use DLOOKUP method to look for your SSN
-
vCheckEntry = DLookup("[SSN_ID]", "tblSSN", "[SSN_ID] = '" & Me.txtSSN & "'")
-
If vCheckEntry = True Then
-
MsgBox ("SSN already exists. Please change it.")
-
Me.txtSSN.SetFocus
-
Else
-
' everyhting OK - do nothing
-
End If
-
By the way don't put your message text in '[code]' brackets. It is hard to read.
cheers,
Which part of the world are you from.....??? Myself from India....
Sajit
Thank you...
it works... the only change which i need to do was to change the variable type from Variant to Boolean.
Thanks once again
Sajit
Sign in to post your reply or Sign up for a free account.
Similar topics
by: John Simmons |
last post by:
How is it that even though I have the column "username" in my database set
as a Primary key, using my PHP script to add new users to the database works
without any errors even when signing up using...
|
by: Ghulam Farid |
last post by:
Hi
i have a table with primary key defined on col1 and col2. now i want to
have col3 also included in primary key. when i alter the table it gives
me error for duplicate rows. there is an option...
|
by: Mavis Tilden |
last post by:
Hi all,
So I've been reading the newsgroups, and reading a few books trying to learn
SQL and SQL Server 2000. The books tell me I need a Primary Key, and that
every table should have one. I know...
|
by: 101 |
last post by:
Taking a course on SQL. They are saying you can get better performance by
having multiple files for a group.
They then graphically show an example of "Primary" with multiple data files.
I have...
|
by: serge |
last post by:
I ran into a table that is used a lot. Well less than
100,000 records. Maybe not a lot of records but i believe
this table is used often. The table has 26 fields, 9 indexes
but no Primary Key at...
|
by: shenanwei |
last post by:
I have a primary server and backup server located in different physical
sites.
The primary server is live and ship logs to backup site every 5
minutes.
The primary server is being full online...
|
by: misscrf |
last post by:
Ok I have 2 issues.
1) I have a main candidate form with 2 subforms on a tab control:
http://www.geocities.com/misscrf/images/contactcontinouscheckbox.jpg
I have been encouraged to add these...
|
by: Thomas A. Anderson |
last post by:
I am a bit confused in creating a composite primary key. I have three table
with two of the tables containing primary keys. I have two of the tables
(each with a primary key) having one to many...
|
by: Challenge |
last post by:
Hi,
I got error, SQL1768N Unable to start HADR. Reason code = "7", when I
tried to start hadr primary database. Here are the hadr configuration
of my primary db:
HADR database role ...
|
by: Peter |
last post by:
I am interested in informed feedback on the use of Constraints, Primary Keys
and Unique.
The following SQL statement creates a Bands tables for a database of
bookings Bands into Venues, where the...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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...
|
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...
|
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: 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...
|
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,...
| |