A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Duplicate Problem with control



 
 
Thread Tools Display Modes
  #1  
Old October 11th, 2006, 02:19 AM posted to microsoft.public.access.forms
Jay
external usenet poster
 
Posts: 43
Default Duplicate Problem with control

I have form with a control that is named AccNum. It does not allow
duplicates. When a user types in a number in the AccNum control it
displays a duplicates not allowed window. At this time the user must
type in a bogus number and then delete the record.

Is there a way to stop this from happening when a duplicate is typed in the
control. Maybe a window that notifies the user and then it returns to
a previous record and then cancells the data input in the AccNum control.
I had looked at the duplicates on this issue and can't get any code to work.

  #2  
Old October 11th, 2006, 02:53 AM posted to microsoft.public.access.forms
Jay
external usenet poster
 
Posts: 43
Default Duplicate Problem with control

"Duane Hookom" DuaneAtNoSpanHookomDotNet wrote:

Teach your users to press the Escape key a couple times.


So simple of a solution. Thanks.



I just found this one on google and made it work.
I just changed strStudentNumber to what I use AccNum.




By placing the following code sample into the Before Update event of the
Student Number field in the main form, this will prevent the duplication,
raise a custom error message and return the user to the original record for
the Student:
Private Sub strStudentNumber_BeforeUpdate(Cancel As Integer)

'*********************************
'Code sample courtesy of srfreeman
'*********************************

Dim SID As String
Dim stLinkCriteria As String
Dim rsc As DAO.Recordset

Set rsc = Me.RecordsetClone

SID = Me.strStudentNumber.Value
stLinkCriteria = "[strStudentNumber]=" & "'" & SID & "'"

'Check StudentDetails table for duplicate StudentNumber
If DCount("strStudentNumber", "tblStudentDetails", stLinkCriteria) 0
Then
'Undo duplicate entry
Me.Undo
'Message box warning of duplication
MsgBox "Warning Student Number " _
& SID & " has already been entered." _
& vbCr & vbCr & "You will now been taken to the record.",
vbInformation _
, "Duplicate Information"
'Go to record of original Student Number
rsc.FindFirst stLinkCriteria
Me.Bookmark = rsc.Bookmark
End If

Set rsc = Nothing
End Sub
  #3  
Old October 11th, 2006, 04:21 AM posted to microsoft.public.access.forms
Duane Hookom
external usenet poster
 
Posts: 2,251
Default Duplicate Problem with control

Teach your users to press the Escape key a couple times.

--
Duane Hookom
MS Access MVP

"Jay" wrote in message
news:jlZWg.1131$rS.133@fed1read05...
I have form with a control that is named AccNum. It does not allow
duplicates. When a user types in a number in the AccNum control it
displays a duplicates not allowed window. At this time the user must
type in a bogus number and then delete the record.

Is there a way to stop this from happening when a duplicate is typed in
the
control. Maybe a window that notifies the user and then it returns to
a previous record and then cancells the data input in the AccNum control.
I had looked at the duplicates on this issue and can't get any code to
work.



  #4  
Old October 11th, 2006, 04:50 AM posted to microsoft.public.access.forms
Gina Whipp
external usenet poster
 
Posts: 3,500
Default Duplicate Problem with control

I have an Order menu that when the user types in a duplicate OrderID a
custom message comes up. This gives them the option to put in a valid Order
number since they are TRYING to enter a new Order anyway.

On the Form_Error event...

Dim strMsg As String

If DataErr = 3022 Then
Response = acDataErrContinue
strMsg = "The Order Number you selected is already in use, " _
& "you MUST select another Order Number!"
MsgBox strMsg
DoCmd.GoToControl "txtOrderID"
End If

HTH,
Gina Whipp

"Jay" wrote in message
news:jlZWg.1131$rS.133@fed1read05...
I have form with a control that is named AccNum. It does not allow
duplicates. When a user types in a number in the AccNum control it
displays a duplicates not allowed window. At this time the user must
type in a bogus number and then delete the record.

Is there a way to stop this from happening when a duplicate is typed in
the
control. Maybe a window that notifies the user and then it returns to
a previous record and then cancells the data input in the AccNum control.
I had looked at the duplicates on this issue and can't get any code to
work.



  #5  
Old October 13th, 2006, 03:13 AM posted to microsoft.public.access.forms
Jay
external usenet poster
 
Posts: 43
Default Duplicate Problem with control

Gina Whipp wrote:

I have an Order menu that when the user types in a duplicate OrderID a
custom message comes up. This gives them the option to put in a valid
Order number since they are TRYING to enter a new Order anyway.

On the Form_Error event...

Dim strMsg As String

If DataErr = 3022 Then
Response = acDataErrContinue
strMsg = "The Order Number you selected is already in use, " _
& "you MUST select another Order Number!"
MsgBox strMsg
DoCmd.GoToControl "txtOrderID"
End If

HTH,
Gina Whipp

"Jay" wrote in message
news:jlZWg.1131$rS.133@fed1read05...
I have form with a control that is named AccNum. It does not allow
duplicates. When a user types in a number in the AccNum control it
displays a duplicates not allowed window. At this time the user must
type in a bogus number and then delete the record.

Is there a way to stop this from happening when a duplicate is typed in
the
control. Maybe a window that notifies the user and then it returns to
a previous record and then cancells the data input in the AccNum control.
I had looked at the duplicates on this issue and can't get any code to
work.



Thank you. I will use it too.
  #6  
Old October 13th, 2006, 05:25 AM posted to microsoft.public.access.forms
Gina Whipp
external usenet poster
 
Posts: 3,500
Default Duplicate Problem with control

Welcome, thanks for posting back!

Gina Whipp

"Jay" wrote in message
news:XjEXg.1265$rS.369@fed1read05...
Gina Whipp wrote:

I have an Order menu that when the user types in a duplicate OrderID a
custom message comes up. This gives them the option to put in a valid
Order number since they are TRYING to enter a new Order anyway.

On the Form_Error event...

Dim strMsg As String

If DataErr = 3022 Then
Response = acDataErrContinue
strMsg = "The Order Number you selected is already in use, " _
& "you MUST select another Order Number!"
MsgBox strMsg
DoCmd.GoToControl "txtOrderID"
End If

HTH,
Gina Whipp

"Jay" wrote in message
news:jlZWg.1131$rS.133@fed1read05...
I have form with a control that is named AccNum. It does not allow
duplicates. When a user types in a number in the AccNum control it
displays a duplicates not allowed window. At this time the user must
type in a bogus number and then delete the record.

Is there a way to stop this from happening when a duplicate is typed in
the
control. Maybe a window that notifies the user and then it returns to
a previous record and then cancells the data input in the AccNum
control.
I had looked at the duplicates on this issue and can't get any code to
work.



Thank you. I will use it too.



 




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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 10:27 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.