473,406 Members | 2,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Error Stopping Duplicate Entries

Hello! I'm still rather new to using code in access. I've come across
a problem that I'm having difficulty troubleshooting. Any assistance
would be greatly appreciated!

I've set up a form where an order number is entered. I have entered
code where if an order number is entered that is a duplicate, a message
box will pop up and tell you so that you can change the number. The
code works perfect for telling you if there's a duplicate or not.

The problem I'm having is that if someone mistakenly types in
information they didn't mean to go to that field and try to delete it
out it bombs. I get an error that says Run-time error '-2147217900
(90040e14)' Syntax error (missing operator) in query expression
'OrderNo='. Then asks me to end or debug. I'll paste the code below.
If anyone has any suggestions or ideas I'd appreciate it!

Private Sub txtOrderNo_BeforeUpdate(Cancel As Integer)

Dim rs As New ADODB.Recordset

rs.Open "SELECT * FROM tblInbDiscrepancyLog WHERE OrderNo=" &
txtOrderNo, CurrentProject.Connection, adOpenStatic, adLockReadOnly

If rs.RecordCount 0 Then

MsgBox "Warning Order Number " _
& Me.txtOrderNo.Value & " has already been entered." _
& vbCr & vbCr & "Please enter a different order
number.", vbInformation _
, "Duplicate Information"

End If

End Sub

Nov 1 '06 #1
4 2154
"afr0ninja" <mo**************@gmail.comwrote in message
<11********************@m73g2000cwd.googlegroups.c om>:
Hello! I'm still rather new to using code in access. I've come
across a problem that I'm having difficulty troubleshooting. Any
assistance would be greatly appreciated!

I've set up a form where an order number is entered. I have entered
code where if an order number is entered that is a duplicate, a
message box will pop up and tell you so that you can change the
number. The code works perfect for telling you if there's a
duplicate or not.

The problem I'm having is that if someone mistakenly types in
information they didn't mean to go to that field and try to delete it
out it bombs. I get an error that says Run-time error '-2147217900
(90040e14)' Syntax error (missing operator) in query expression
'OrderNo='. Then asks me to end or debug. I'll paste the code
below. If anyone has any suggestions or ideas I'd appreciate it!

Private Sub txtOrderNo_BeforeUpdate(Cancel As Integer)

Dim rs As New ADODB.Recordset

rs.Open "SELECT * FROM tblInbDiscrepancyLog WHERE OrderNo=" &
txtOrderNo, CurrentProject.Connection, adOpenStatic, adLockReadOnly

If rs.RecordCount 0 Then

MsgBox "Warning Order Number " _
& Me.txtOrderNo.Value & " has already been entered." _
& vbCr & vbCr & "Please enter a different order
number.", vbInformation _
, "Duplicate Information"

End If

End Sub
I think I'd try to test for content first, and perhaps if it's numeric

if len(me!txtOrderNo.Value & vbNullString) then
if me!txtOrderNo.Value like _
string(len(me!txtOrderNo.Value), "#") then
' do your testing here
else
' not numeric
end if
else
' no contents, no testing?
end if

I'm usually more inclined to do tests in (or also in) the before
update event of the form, which is triggered whenever an attempt
to save is made.

Around these NGs you'll probably be adviced to use DAO on Jet tables,
but if you're using ADO, I'm very reluctant to rely upon the
..RecordCount property, and would rather use the following construct
to test wether the recordset contained records or not

if ((not rs.bof) and (not rs.eof)) then
' the recordset contains records...
end if

--
Roy-Vidar
Nov 1 '06 #2
Hello! Thank you for your assistance!

I am having some issues with what you've suggested. If I use the code
you've sugested it processes the information without error, however it
no longer alerts you when you have a duplicate entry as my origional
code did.

The text number is numeric. And the code I origionally had works
almost flawlessly. The only issue I was having with it is that if
someone starts to type in an order number and they didn't mean to enter
it into that form, once they delete the mistaken order number out it
bombs.

Any other suggestions or advice would be greatly appreciated.

Nov 6 '06 #3
"afr0ninja" <mo**************@gmail.comwrote in message
<11**********************@f16g2000cwb.googlegroups .com>:
Hello! Thank you for your assistance!

I am having some issues with what you've suggested. If I use the
code you've sugested it processes the information without error,
however it no longer alerts you when you have a duplicate entry as my
origional code did.

The text number is numeric. And the code I origionally had works
almost flawlessly. The only issue I was having with it is that if
someone starts to type in an order number and they didn't mean to
enter it into that form, once they delete the mistaken order number
out it bombs.

Any other suggestions or advice would be greatly appreciated.
If you post your current code for the event, someone might assist.

--
Roy-Vidar
Nov 6 '06 #4
Well.. Since reposting I've done some more messing around and I think I
got it figured out. Below is what worked. Thank you very much for
your help!

Private Sub txtOrderNo_BeforeUpdate(Cancel As Integer)

If Len(Me!txtOrderNo.Value & vbNullString) Then
If Me!txtOrderNo.Value Like _
String(Len(Me!txtOrderNo.Value), "#") Then

Dim rs As New ADODB.Recordset

rs.Open "SELECT * FROM tblInbTracking WHERE OrderNo=" & txtOrderNo,
CurrentProject.Connection, adOpenStatic, adLockReadOnly

If rs.RecordCount 0 Then

MsgBox "Warning Order Number " _
& Me.txtOrderNo.Value & " has already been entered." _
& vbCr & vbCr & "Please enter a different order
number.", vbInformation _
, "Duplicate Information"

End If

Else

' not numeric

End If

Else

' no contents, no testing?

End If

End Sub

Nov 7 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: monika | last post by:
hi ... I want to do error handling in my application. I have made a complete application. but when I encounter errors (like mentioned below) I want to do error handling. how can I do it? I...
0
by: Gary Lundquest | last post by:
I have an application with MS Access 2000 as the front end and MySQL as the back end. All was well until I upgraded the MySQL (Linux) server. The Problem: I insert data into a cumulative table....
1
by: Gary Lundquest | last post by:
It appears to me that MySQL version 4 returns an error messge when doing an Insert that results in duplicate entries. Version 3 did NOT return an error - it dropped the duplicate entries and ran...
1
by: marx | last post by:
I have a bit of a problem and any help would be much appreciated. Problem: I have two dropdown list boxes with same data(all data driven). These are used for two separate entries. For every...
3
by: andreas.maurer1971 | last post by:
Hi all, since a few years I use the following statement to find duplicate entries in a table: SELECT t1.id, t2.id,... FROM table AS t1 INNER JOIN table AS t2 ON t1.field = t2.field WHERE...
5
by: Chris Lasher | last post by:
Hello Pythonistas! I'm looking for a way to duplicate entries in a symmetrical matrix that's composed of genetic distances. For example, suppose I have a matrix like the following: A B ...
5
by: Manish | last post by:
The topic is related to MySQL database. Suppose a table "address" contains the following records ------------------------------------------------------- | name | address | phone |...
1
by: JJ | last post by:
What's best practise in this situation: Upon submitting data input on a detailsview (bound to an objectdatasource), I need to check for a duplicate email address (in an sql database) and present...
4
by: ramdil | last post by:
Hi All I have table and it have around 90000 records.Its primary key is autonumber field and it has also have date column and name, then some other columns Now i have problem with the table,as my...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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
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,...
0
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...

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.