473,395 Members | 1,823 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,395 software developers and data experts.

How to make a message "data can't double"

I have a textbox call Staff_ID, I don't want my user to type the same Staff_ID . So I write the vba code like this

Expand|Select|Wrap|Line Numbers
  1. Private Sub Staff_ID_AfterUpdate()
  2. Dim SID As String
  3. Dim stLinkCriteria As String
  4. Dim rsc As DAO.Recordset
  5.  
  6. Set rsc = Me.RecordsetClone
  7. SID = Staff_ID.Value
  8. stLinkCriteria = "[Staff_ID]=" & "'" & SID & "'"
  9.  
  10.     If DCount("Staff_ID", "[Employee]", stLinkCriteria) > 0 Then
  11.         Me.Undo
  12.         MsgBox "Staff_Id = " & SID & " Already Have..." _
  13.         & vbCr & vbCr & "Type another staff_ID.", vbInformation _
  14.         , "Data cannot Double"
  15.         Me.New.SetFocus
  16.  
  17.         rsc.FindFirst stLinkCriteria
  18.         Me.Bookmark = rsc.Bookmark
  19.         End If
  20. Set rsc = Nothing
  21. End Sub
The problem when I try it I Have a message " Run time Error "3420" Object Invalid or no longer set.When I open the debug at ( rsc.findfirst stlinkcriteeria ) have a yellow color.

Please help me to solve this problem. Thank you
Feb 19 '12 #1

✓ answered by Mihail

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2.     If DCount("[Staff_ID]", "Employee", "[Staff_ID]='" & Staff_ID & "'") Then
  3.         MsgBox ("Existent ID")
  4.         Cancel = True
  5.     End If
  6. End Sub

3 1654
Mihail
759 512MB
Access manage itself your problem.
Assuming that the Staff_ID text box is bound to Staff_ID field all you need is to set the Indexed property for Staff_ID field (table design view -> General tab) to Yes (No Duplicates).

This way Access do not allow duplicates for this field.

By the way, the event _AfterUpdate() is not useful because you need to looking for duplicates _BeforeUpdate (BEFORE the value is passed to table, isn't it ?)

Good luck !
Feb 19 '12 #2
thanks, but it still no work, maybe you have another way for my case, all I need is making my application look like a professional. Thanks
Feb 22 '12 #3
Mihail
759 512MB
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2.     If DCount("[Staff_ID]", "Employee", "[Staff_ID]='" & Staff_ID & "'") Then
  3.         MsgBox ("Existent ID")
  4.         Cancel = True
  5.     End If
  6. End Sub
Feb 22 '12 #4

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

Similar topics

3
by: Mensan | last post by:
I am trying to compute the differnece between two dwords in visual basic and keep getting the wrong value being computed. I have the following structure defind: Public Type HighLowQuote...
3
by: H. S. | last post by:
Hi, I am trying to compile these set of C++ files and trying out class inheritence and function pointers. Can anybody shed some light why my compiler is not compiling them and where I am going...
5
by: eliffman | last post by:
I'm trying to populate an array with the records from a recordset. But I'm getting an error. Here's the code: Dim db As Database, qd As QueryDef, rs As Recordset Dim MyArray() As Double, i As...
2
by: Jean | last post by:
Hello everyone, I was having the following problem with a query, and after failing to find a similar solution on these newsgroups I decided to post here. I am quite new to Access, so would...
22
by: bq | last post by:
Hello, Two questions related to floating point support: What C compilers for the wintel (MS Windows + x86) platform are C99 compliant as far as <math.h> and <tgmath.h> are concerned? What...
4
by: michi | last post by:
Hello How can I convert a string to double with a decimal point as seperator? ***CODE**** strNumber ="12.00" dblDouble = Cdbl(strNumber) ****
6
by: P. Prosper | last post by:
Hello, Sorry for the cross-posting, I first posted this message to the vb.6 NG (wrong group) <g>. Are there any add-in or tools out there (for VB.NET ) that would allow one to drag and drop...
12
by: Zero | last post by:
Hi everybody, i want to write a small program, which shows me the biggest and smallest number in dependance of the data type. For int the command could be: ...
11
by: sofeng | last post by:
I'm not sure if "data hiding" is the correct term, but I'm trying to emulate this object-oriented technique. I know C++ probably provides much more than my example, but I'd just like some feedback...
3
by: Steve Folly | last post by:
Hi, I had a problem in my code recently which turned out to be the 'the "static initialization order fiasco"' problem (<http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.12>) The FAQ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.