![]() |
|
|
#1
|
|||
|
|||
|
hello guys, i am new to this site and new to access.
i am using Access 2007 to create a DB for my IGCSE project. i wanted to create a msg box if a user enter a duplicate data. but now even if i enter diff data it still says that the number is being used. here is the code..by the way this code won't take me to the to the record even if i enter a used number. Thanks. Private Sub PostNumber_BeforeUpdate(Cancel As Integer) Dim SID As String Dim stLinkCriteria As String Dim rsc As DAO.Recordset Set rsc = Me.RecordsetClone SID = Me.[Post Number].Value stLinkCriteria = "[PostNumber]=" & "'" & SID & "'" 'Check Employee Table table for duplicate If DCount("PostNumber", "Employee Table", stLinkCriteria) > 0 Then 'Undo duplicate entry Me.Undo 'Undo this entry. 'Message box warning of duplication MsgBox "Warning Post Number " _ & SID & " has already been entered." _ & vbCr & vbCr & "You will now been taken to the record.", _ vbInformation, "Duplicate Information" 'Go to record of original record 'rsc.FindFirst stLinkCriteria 'Me.Bookmark = rsc.Bookmark End If Set rsc = Nothing End Sub |
|
#2
|
||||
|
||||
|
If you want to go to the previous record for the entry then use the AfterUpdate event rather than the BeforeUpdate event of the control.
__________________
(RG for short) aka Allan Bunch MS Access MVP - WinXP Pro, Win7 - acXP, ac07 If your issue is resolved...follow this link for directions on how to use the Solved thread tool! Teaching is not filling a bucket but lighting a fire. Borrowed quote..."Docendo discimus" |
|
#3
|
|||
|
|||
|
Quote:
hey mate, am new to access can you tell me how to change it?
|
|
#4
|
||||
|
||||
|
Move the code you have to the AfterUpdate event of the same control and un-comment the lines and give it a try.
__________________
(RG for short) aka Allan Bunch MS Access MVP - WinXP Pro, Win7 - acXP, ac07 If your issue is resolved...follow this link for directions on how to use the Solved thread tool! Teaching is not filling a bucket but lighting a fire. Borrowed quote..."Docendo discimus" |
|
#5
|
|||
|
|||
|
Quote:
sorry but can u be more specific if u dnt mind? |
|
#6
|
||||
|
||||
|
Can you move the code in the BeforeUpdate event to the AfterUpdate event?
__________________
(RG for short) aka Allan Bunch MS Access MVP - WinXP Pro, Win7 - acXP, ac07 If your issue is resolved...follow this link for directions on how to use the Solved thread tool! Teaching is not filling a bucket but lighting a fire. Borrowed quote..."Docendo discimus" |
|
#7
|
|||
|
|||
|
Quote:
ok in the m on the properth sheet and i see the event.... you mean copy the code and change to the AfterupDate? what i need to change in the code so it can work? |
|
#8
|
|||
|
|||
|
Quote:
i get this error when i do that. Private Sub PostNumber_AfterUpdate() |
|
#9
|
||||
|
||||
|
In solving this problem how about telling us what an IGCSE project is? Do you have an error message? Maybe an error Number? Post what you have starting with Private and ending with End Sub.
__________________
(RG for short) aka Allan Bunch MS Access MVP - WinXP Pro, Win7 - acXP, ac07 If your issue is resolved...follow this link for directions on how to use the Solved thread tool! Teaching is not filling a bucket but lighting a fire. Borrowed quote..."Docendo discimus" |
|
#10
|
|||
|
|||
|
Quote:
the project is one the i choose to make about HR. Private Sub PostNumber_AfterUpdate() Dim SID As String Dim stLinkCriteria As String Dim rsc As DAO.Recordset Set rsc = Me.RecordsetClone SID = Me.PostNumber.Value stLinkCriteria = "[PostNumber]=" & "'" & SID & "'" 'Check Employee Table table for duplicate If DCount("PostNumber", "Employee Table", stLinkCriteria) > 0 Then 'Undo duplicate entry Me.Undo 'Message box warning of duplication MsgBox "Warning Post Number " _ & SID & " has already been entered." _ & vbCr & vbCr & "You will now been taken to the record.", _ vbInformation, "Duplicate Information" 'Go to record of original record 'rsc.FindFirst stLinkCriteria 'Me.Bookmark = rsc.Bookmark End If Set rsc = Nothing End Sub even with this code i still get the box that says "Dublicate Information" Warning Post Number 11 has already been entered. You Will now been taken to the record. but the record 11 isn't there i am sure of that.. |
|
#11
|
||||
|
||||
|
What does IGCSE mean?
__________________
(RG for short) aka Allan Bunch MS Access MVP - WinXP Pro, Win7 - acXP, ac07 If your issue is resolved...follow this link for directions on how to use the Solved thread tool! Teaching is not filling a bucket but lighting a fire. Borrowed quote..."Docendo discimus" |
|
#12
|
|||
|
|||
|
|
|
#13
|
||||
|
||||
|
Is the [PostNumber] field a NUMERIC or TEXT field?
__________________
(RG for short) aka Allan Bunch MS Access MVP - WinXP Pro, Win7 - acXP, ac07 If your issue is resolved...follow this link for directions on how to use the Solved thread tool! Teaching is not filling a bucket but lighting a fire. Borrowed quote..."Docendo discimus" |
|
#14
|
|||
|
|||
|
Numeric (Number) my friend |
|
#15
|
||||
|
||||
|
So you do not want the single quotes:
Code:
Private Sub PostNumber_AfterUpdate()
Dim SID As String
Dim stLinkCriteria As String
Dim rsc As DAO.Recordset
Set rsc = Me.RecordsetClone
SID = Me.PostNumber
stLinkCriteria = "[PostNumber]=" & SID
'Check Employee Table table for duplicate
If DCount("PostNumber", "Employee Table", stLinkCriteria) > 0 Then
'Undo duplicate entry
Me.Undo
'Message box warning of duplication
MsgBox "Warning Post Number " _
& SID & " has already been entered." _
& vbCr & vbCr & "You will now been taken to the record.", _
vbInformation, "Duplicate Information"
'Go to record of original record
rsc.FindFirst stLinkCriteria
Me.Bookmark = rsc.Bookmark
End If
Set rsc = Nothing
End Sub
__________________
(RG for short) aka Allan Bunch MS Access MVP - WinXP Pro, Win7 - acXP, ac07 If your issue is resolved...follow this link for directions on how to use the Solved thread tool! Teaching is not filling a bucket but lighting a fire. Borrowed quote..."Docendo discimus" |
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Duplicate record failure | bugchaser | Access | 5 | 05-21-2009 06:38 AM |
| If duplicate record, go to original record | BigBear | Forms | 1 | 03-30-2009 07:27 AM |
| Duplicate the record in form and subform to a different table | mwillis929 | Forms | 0 | 01-06-2009 11:17 AM |
| Deleting Record Contents, not complete record... | Charles Waters | Access | 2 | 06-24-2008 10:00 AM |
| i need record dividers | dunston | Reports | 1 | 11-11-2006 04:57 PM |