The lines Dim bClose and bColor are not needed. Sorry for including them.
Thanks!
Joe
Main Topics
Browse All TopicsPlease help me I need help in writing VB code in MS Access database module.
I want to validate a form with the duplicate invoice no ie.. User enters the duplicate invoice number in the text box then, i should display a warning message saying Invoice number already exists in the database. The Invoice number in the database datatype is text field
Can you guys please help me writing a code for checking the duplicate value for invoice no and displaying error message ,otherwise proceed with the insert.
I am planning to write code in the event procedure
Private Sub NextInvoice_Click()
End Sub
Can you also explain how to attach a vb code to the command button or Text box and when to perform validation in the form
Regards,
srujana
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
HaryMary,
If I set the Indexed property to Yes (Duplicates OK) selected. How will user know, that they entered the duplicate Invoice no
Shouldn't I have to give the error message that Invoice Nu mber already exists.
Can you please tell me should I write a code for Duplicate Invoice Number or not.
When I saw the database, Indexed property is already set to that.
Hi joekendall,
Thanks , I think I have to use your code to display an error message,
But When I copied your code an pasted and changed the table name and field names(FYI - My table name and Field name has spaces)
I am getting syntax error in the code ie in select statement
When i run the code
The error is
Run -time error '3075'
Syntax error(Missing Operator) in query expression 'Invoice No = '1800277''.
Please help me debug the code
Private Sub txtinvoice_BeforeUpdate(Ca
Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("S
If Not rs.BOF And Not rs.EOF Then
MsgBox "Error - Invoice #" & txtinvoice & " already exists!"
Cancel = True
End If
rs.Close
Set rs = Nothing
End Sub
You need brackets around the Table name and the Field name.
Set rs = CurrentDb.OpenRecordset("S
That is why it is a bad idea to include spaces in table and field names. If you ever decide to upsize to another database (Oracle, etc.), it can cause you alot of problems. It is best to include an underscore(_) for a space.
Thanks!
Joe
This question has been abandoned and needs to be finalized.
You can accept an answer, split the points, or get a refund (information at http:/help/closing.jsp)
If you need a moderator to help you, post a question at Community Support (http:/Community_Support/)
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
nexusnation, cleanup volunteer
sru578,
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:
RECOMMENDATION: split points between joekendall http:#8888274 and HaryMary http:#8888388
Please leave any comments here within 7 days.
-- Please DO NOT accept this comment as an answer ! --
Thanks,
jadedata
EE Cleanup Volunteer
Business Accounts
Answer for Membership
by: joekendallPosted on 2003-07-09 at 12:43:55ID: 8888274
You can write the code in the BeforeUpdate event of the text box. You can basically see if the invoice number exists in the table using one of the domain functions or querying the table yourself.
ncel As Integer)
ELECT * FROM tblInvoice WHERE InvoiceNbr = '" & txtinvoice & "'")
Something like this should get you going.
Private Sub txtInvoice_BeforeUpdate(Ca
Dim rs As DAO.Recordset
Dim bClose As Boolean
Dim bColor As Boolean
Set rs = CurrentDb.OpenRecordset("S
If Not rs.BOF And Not rs.EOF Then
MsgBox "Error - Invoice #" & txtinvoice & " already exists!"
Cancel = True
End If
rs.Close
Set rs = Nothing
End Sub
Thanks!
Joe