473,473 Members | 2,170 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Why can't I add a new pNumber??

83 New Member
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
Attached Files
File Type: zip TestToSeeIfNumberPresent.zip (26.8 KB, 71 views)
Apr 14 '15 #1
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
Apr 14 '15 #2
jforbes
1,107 Recognized Expert Top Contributor
I pulled the problematic code out of your database for you:
Expand|Select|Wrap|Line Numbers
  1. Private Sub pNumber_BeforeUpdate(Cancel As Integer)
  2.     If LookUp("pNumber", "tbldetails", Me.pNumber, eCount) > 0 Then
  3.         MsgBox "this Pmkeys Already Exists, Try Again", vbExclamation, "Cannot Update"
  4.             SendKeys "{ESC}"
  5.             SendKeys "{ESC}"
  6.     End If
  7. End Sub
  8.  
  9. Function LookUp(sField As String, sTable As String, sCriteria As String, _
  10.                 Optional AggFunc As Integer = 0) As Variant '
  11. On Error GoTo ErrorHandler
  12. Dim sSQL As String
  13. Dim sAggFunc As String
  14. Dim db As DAO.Database
  15. Dim rs As DAO.Recordset
  16. If sCriteria <> "" Then sCriteria = " WHERE (" & sCriteria & ")"
  17. If AggFunc > 0 Then
  18.     Select Case AggFunc
  19.         Case 1
  20.             sAggFunc = "Sum("
  21.         Case 2
  22.             sAggFunc = "Avg("
  23.         Case 3
  24.             sAggFunc = "Min("
  25.         Case 4
  26.             sAggFunc = "Max("
  27.         Case 5
  28.             sAggFunc = "Count("
  29.         Case 6
  30.             sAggFunc = "StDev("
  31.         Case 7
  32.             sAggFunc = "Var("
  33.         Case 8
  34.             sAggFunc = "First("
  35.         Case 9
  36.             sAggFunc = "Last("
  37.     End Select
  38.     sSQL = "SELECT " & sAggFunc & sField & ") AS LookUpField " _
  39.         & "FROM " & sTable _
  40.         & sCriteria & ";"
  41.     Else
  42.     sSQL = "SELECT " & sField & " AS LookUpField " _
  43.         & "FROM " & sTable _
  44.         & sCriteria & " " _
  45.         & "GROUP BY " & sField & " " _
  46.         & "ORDER BY " & sField & " DESC;"
  47. End If
  48. Debug.Print sSQL
  49. Set db = CurrentDb
  50. Set rs = db.OpenRecordset(sSQL)
  51.     rs.MoveLast
  52.     rs.MoveFirst
  53. LookUp = rs.Fields("LookUpField")
  54. rs.Close
  55. GoTo ThatsIt
  56. ErrorHandler:
  57.     Select Case Err.Number
  58.         Case 3021, 3061, 3075, 3079
  59.         Case 3024, 3043, 3044 'exclude "Cannot find Table" so error propagates
  60.         Err.Raise -65536, "Lookup", Err.Description
  61.         Case Else
  62.             MsgBox "Error " & Err.Number & ": " & Err.Description & vbCrLf & "in LookUp"
  63.     End Select
  64.     LookUp = Null
  65. ThatsIt:
  66. Set rs = Nothing
  67. Set db = Nothing
  68. End Function
  69.  
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:
Expand|Select|Wrap|Line Numbers
  1. If DCount("pNumber", "tbldetails", "pNumber=" & Me.pNumber) > 0 Then
Apr 14 '15 #3
hrprabhu
83 New Member
Thanks jforbes. Just came to the same conclusion after posting yesterday.
Apr 15 '15 #4

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

Similar topics

3
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...
4
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...
9
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....
0
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...
16
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...
2
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...
3
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...
2
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 ...
1
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.
6
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? ...
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
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...
1
isladogs
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...
0
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...
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...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
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...

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.