Hello one and all,
My apologies I am still using Access 2003
Have a look at the small attached database. I can not understand why I can not add a new number!
on opening the database it opens form frmdetails. Click on add new record and it takes you to another form. here you click add new record and input any 7 digit number and it rejects.
Thanks in advance
Regards to all
Raghu Prabhu
3 1208 jimatqsi 1,271
Recognized Expert Top Contributor
Most folks here are not going to download an attachment due to concerns about malware. Please list the code involved, and add more detail.
Also, why make your user click Add New Record if they already clicked to open the form to add a new record. Their intent is already clear.
Jim
jforbes 1,107
Recognized Expert Top Contributor
I pulled the problematic code out of your database for you: - Private Sub pNumber_BeforeUpdate(Cancel As Integer)
-
If LookUp("pNumber", "tbldetails", Me.pNumber, eCount) > 0 Then
-
MsgBox "this Pmkeys Already Exists, Try Again", vbExclamation, "Cannot Update"
-
SendKeys "{ESC}"
-
SendKeys "{ESC}"
-
End If
-
End Sub
-
-
Function LookUp(sField As String, sTable As String, sCriteria As String, _
-
Optional AggFunc As Integer = 0) As Variant '
-
On Error GoTo ErrorHandler
-
Dim sSQL As String
-
Dim sAggFunc As String
-
Dim db As DAO.Database
-
Dim rs As DAO.Recordset
-
If sCriteria <> "" Then sCriteria = " WHERE (" & sCriteria & ")"
-
If AggFunc > 0 Then
-
Select Case AggFunc
-
Case 1
-
sAggFunc = "Sum("
-
Case 2
-
sAggFunc = "Avg("
-
Case 3
-
sAggFunc = "Min("
-
Case 4
-
sAggFunc = "Max("
-
Case 5
-
sAggFunc = "Count("
-
Case 6
-
sAggFunc = "StDev("
-
Case 7
-
sAggFunc = "Var("
-
Case 8
-
sAggFunc = "First("
-
Case 9
-
sAggFunc = "Last("
-
End Select
-
sSQL = "SELECT " & sAggFunc & sField & ") AS LookUpField " _
-
& "FROM " & sTable _
-
& sCriteria & ";"
-
Else
-
sSQL = "SELECT " & sField & " AS LookUpField " _
-
& "FROM " & sTable _
-
& sCriteria & " " _
-
& "GROUP BY " & sField & " " _
-
& "ORDER BY " & sField & " DESC;"
-
End If
-
Debug.Print sSQL
-
Set db = CurrentDb
-
Set rs = db.OpenRecordset(sSQL)
-
rs.MoveLast
-
rs.MoveFirst
-
LookUp = rs.Fields("LookUpField")
-
rs.Close
-
GoTo ThatsIt
-
ErrorHandler:
-
Select Case Err.Number
-
Case 3021, 3061, 3075, 3079
-
Case 3024, 3043, 3044 'exclude "Cannot find Table" so error propagates
-
Err.Raise -65536, "Lookup", Err.Description
-
Case Else
-
MsgBox "Error " & Err.Number & ": " & Err.Description & vbCrLf & "in LookUp"
-
End Select
-
LookUp = Null
-
ThatsIt:
-
Set rs = Nothing
-
Set db = Nothing
-
End Function
-
On line 2 the code calls the custom function Lookup() and there is no need for this function and the extra code (that isn't quite working).
I would replace it with: - If DCount("pNumber", "tbldetails", "pNumber=" & Me.pNumber) > 0 Then
Thanks jforbes. Just came to the same conclusion after posting yesterday.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Aaron Brockhurst |
last post by:
Hi
Can anyone help?
I cant get my php script to insert or delete records into a mysql
table. I can view them all fine but that's about it. I've checked
the user permissions on mysql and...
|
by: gregsands |
last post by:
Hi
I have read all (ok most) of the posts relating to "Call to undefined
function mysql_connect()", read the manual on PHP.net and done
eveything thats ive been asked to do but cant get PHP to...
|
by: Dan K. |
last post by:
Hi Folks,
Problem is, that on one of my controls the DEL key wont work in
textboxes. i have different controls of this kind in my app and this
is the only one the DEL Key wont do his job....
|
by: Tillmann Neben |
last post by:
As the topic already says, i just cant get it working. I am using
"ftp-mode" to get the files onto the server instead of using frontpage
extension.
When I try to debug, VS tells me, that the...
|
by: Mike Fellows |
last post by:
when i load my windows form i populate a combobox i use the code below
Dim conn As New System.Data.SqlClient.SqlConnection(strConn)
Dim sql As String = "AllLenders"
Dim da As New...
| |
by: g35rider |
last post by:
Hi, I have the following code that is giving this error, I cant
simplify the code, I was just testing some theory for something we are
doing and was getting an issue here. Please someone point out...
|
by: arun.hallan |
last post by:
Hi,
I'm having problems with authentication.
I have a set of users that are allowed to use a webpage. They are in
domain A.
My goal is to get the username of these users and then check them...
|
by: andrewanderson |
last post by:
hi can anyone help me with this prog. cant find the prob why it cant display
cout<<"This is the display of your transaction"<<endl;
ifstream fobj; //declare input file stream
...
|
by: Nagaraj |
last post by:
hi all,
I have simple basic c++ program "hello world" which i cant compile on
linux system. I have given extension as .C. please tell me how to
compile C++ programs on Linux.
|
by: WolfgangS |
last post by:
Ok first off, i am a total beginner at this groups stuff and i have no
clue how this works. This is probabaly the wrong group for my problem
but i will post it anyways. Learning by doing right?
...
|
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: 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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |