Microsoft Access Forums

Go Back   Microsoft Access Forums > Access Forums > Access

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 06-23-2009, 09:24 AM
islandboy islandboy is offline Windows Vista Access 2007 (version 12.0)
Advanced Beginner
 
Join Date: Jun 2009
Posts: 63
islandboy is on a distinguished road
Default If duplicate record, go to original record

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
Reply With Quote
  #2  
Old 06-23-2009, 10:57 AM
RuralGuy's Avatar
RuralGuy RuralGuy is online now Windows 7 Access 2007 (version 12.0)
Administrator
 
Join Date: Mar 2007
Location: 8300' in the Colorado Rocky Mountains
Posts: 4,263
RuralGuy will become famous soon enoughRuralGuy will become famous soon enough
Default

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"
Reply With Quote
  #3  
Old 06-23-2009, 09:02 PM
islandboy islandboy is offline Windows Vista Access 2007 (version 12.0)
Advanced Beginner
 
Join Date: Jun 2009
Posts: 63
islandboy is on a distinguished road
Default

Quote:
Originally Posted by RuralGuy View Post
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.

hey mate,

am new to access can you tell me how to change it?
Reply With Quote
  #4  
Old 06-24-2009, 05:05 AM
RuralGuy's Avatar
RuralGuy RuralGuy is online now Windows 7 Access 2007 (version 12.0)
Administrator
 
Join Date: Mar 2007
Location: 8300' in the Colorado Rocky Mountains
Posts: 4,263
RuralGuy will become famous soon enoughRuralGuy will become famous soon enough
Default

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"
Reply With Quote
  #5  
Old 06-24-2009, 06:50 AM
islandboy islandboy is offline Windows Vista Access 2007 (version 12.0)
Advanced Beginner
 
Join Date: Jun 2009
Posts: 63
islandboy is on a distinguished road
Default

Quote:
Originally Posted by RuralGuy View Post
Move the code you have to the AfterUpdate event of the same control and un-comment the lines and give it a try.

sorry but can u be more specific if u dnt mind?
Reply With Quote
  #6  
Old 06-24-2009, 07:05 AM
RuralGuy's Avatar
RuralGuy RuralGuy is online now Windows 7 Access 2007 (version 12.0)
Administrator
 
Join Date: Mar 2007
Location: 8300' in the Colorado Rocky Mountains
Posts: 4,263
RuralGuy will become famous soon enoughRuralGuy will become famous soon enough
Default

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"
Reply With Quote
  #7  
Old 06-24-2009, 07:29 AM
islandboy islandboy is offline Windows Vista Access 2007 (version 12.0)
Advanced Beginner
 
Join Date: Jun 2009
Posts: 63
islandboy is on a distinguished road
Default

Quote:
Originally Posted by RuralGuy View Post
Can you move the code in the BeforeUpdate event to the AfterUpdate event?

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?
Reply With Quote
  #8  
Old 06-24-2009, 07:32 AM
islandboy islandboy is offline Windows Vista Access 2007 (version 12.0)
Advanced Beginner
 
Join Date: Jun 2009
Posts: 63
islandboy is on a distinguished road
Default

Quote:
Originally Posted by islandboy View Post
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?

i get this error when i do that.

Private Sub PostNumber_AfterUpdate()
Reply With Quote
  #9  
Old 06-24-2009, 07:41 AM
RuralGuy's Avatar
RuralGuy RuralGuy is online now Windows 7 Access 2007 (version 12.0)
Administrator
 
Join Date: Mar 2007
Location: 8300' in the Colorado Rocky Mountains
Posts: 4,263
RuralGuy will become famous soon enoughRuralGuy will become famous soon enough
Default

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"
Reply With Quote
  #10  
Old 06-24-2009, 07:55 AM
islandboy islandboy is offline Windows Vista Access 2007 (version 12.0)
Advanced Beginner
 
Join Date: Jun 2009
Posts: 63
islandboy is on a distinguished road
Default

Quote:
Originally Posted by RuralGuy View Post
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.


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..
Reply With Quote
  #11  
Old 06-24-2009, 08:13 AM
RuralGuy's Avatar
RuralGuy RuralGuy is online now Windows 7 Access 2007 (version 12.0)
Administrator
 
Join Date: Mar 2007
Location: 8300' in the Colorado Rocky Mountains
Posts: 4,263
RuralGuy will become famous soon enoughRuralGuy will become famous soon enough
Default

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"
Reply With Quote
  #12  
Old 06-24-2009, 08:17 AM
islandboy islandboy is offline Windows Vista Access 2007 (version 12.0)
Advanced Beginner
 
Join Date: Jun 2009
Posts: 63
islandboy is on a distinguished road
Default

Quote:
Originally Posted by RuralGuy View Post
What does IGCSE mean?

http://www.cie.org.uk/qualifications/academic/middlesec/igcse/subject?assdef_id=844
Reply With Quote
  #13  
Old 06-24-2009, 08:25 AM
RuralGuy's Avatar
RuralGuy RuralGuy is online now Windows 7 Access 2007 (version 12.0)
Administrator
 
Join Date: Mar 2007
Location: 8300' in the Colorado Rocky Mountains
Posts: 4,263
RuralGuy will become famous soon enoughRuralGuy will become famous soon enough
Default

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"
Reply With Quote
  #14  
Old 06-24-2009, 08:32 AM
islandboy islandboy is offline Windows Vista Access 2007 (version 12.0)
Advanced Beginner
 
Join Date: Jun 2009
Posts: 63
islandboy is on a distinguished road
Default

Quote:
Originally Posted by RuralGuy View Post
Is the [PostNumber] field a NUMERIC or TEXT field?

Numeric (Number) my friend
Reply With Quote
  #15  
Old 06-24-2009, 08:59 AM
RuralGuy's Avatar
RuralGuy RuralGuy is online now Windows 7 Access 2007 (version 12.0)
Administrator
 
Join Date: Mar 2007
Location: 8300' in the Colorado Rocky Mountains
Posts: 4,263
RuralGuy will become famous soon enoughRuralGuy will become famous soon enough
Default

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"
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


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


All times are GMT -8. The time now is 02:46 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.