My Assistant
![]() ![]() |
|
|
Jul 5 2007, 08:18 PM
Post
#1
|
|
|
UtterAccess VIP Posts: 12,201 From: Tacoma, WA. |
Am using the below borrowed code to check for duplicates The Main Menu has a Command button that opens the form to a New record
CODE DoCmd.OpenForm "frmCharts", acNormal, , , acFormAdd, acWindowNormal and the Code Fires but of course I get a No Current record Error 3021 , If the form is opened showing ALL records the Cose works just fine and I am taken to the Record. Is there a way to open the Form (it is recognizing the Duplicate) when the acformAdd button is used in place of viewing ALL records?CODE Private Sub ChartDate_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.ChartDate.Value stLinkCriteria = "[chartdate]=" & "#" & SID & "#" 'Check StudentDetails table for duplicate StudentNumber If DCount("chartdate", "tblcharts", stLinkCriteria) > 0 Then 'Undo duplicate entry Me.Undo 'Message box warning of duplication MsgBox "Warning This Chart Date " _ & 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 Thank You |
|
|
|
Jul 5 2007, 08:33 PM
Post
#2
|
|
|
UA Forum Administrator Posts: 38,073 From: Birmingham, Alabama USA |
Is SID text .. or a date ???
You have it dim'd as a String .. then are using octothorps as delimters on down in the code. RDH Edited by: R. Hicks on Thu Jul 5 21:53:48 EDT 2007. |
|
|
|
Jul 5 2007, 09:12 PM
Post
#3
|
|
|
UtterAccess VIP Posts: 12,201 From: Tacoma, WA. |
Thank You Ricky
Sorry for the delay thought I had responded earlier. Anyway Yes It is a date and I have changed accordingly in the Dim'd line but same result errors out on this line Me.Bookmark = rsc.Bookmark |
|
|
|
Jul 5 2007, 09:15 PM
Post
#4
|
|
|
UtterAccess VIP Posts: 12,201 From: Tacoma, WA. |
Ricky,
Yes it is a date, I have changed the Dimd line accordingly however still the same result. Errors out on this line Me.Bookmark = rsc.Bookmark Something screwy going on here, I look at the post and my reply is not there so I repost with a reply and the original reply is there ??? Strange Edited by: jmcwk on Thu Jul 5 22:16:27 EDT 2007. |
|
|
|
Jul 5 2007, 09:30 PM
Post
#5
|
|
|
Retired Moderator Posts: 37,716 From: The San Francisco Bay Area |
John -
Try: stLinkCriteria = "[chartdate] = #" & SID & "#" hth, Jack |
|
|
|
Jul 5 2007, 10:10 PM
Post
#6
|
|
|
UtterAccess VIP Posts: 3,071 From: The Land of the Access Ninja's |
John these are my thoughts...
Because you are using acFormAdd when opening the form you are not going to see previously entered records. Therefore when you run your RecordsetClone for your form it would not allow you to find a previous record. This is why when you open the form showing all records your code works. If this proves to be in fact the case I would try the following steps. 1. Write your code first to find out if the value (i.e your date I believe) exists by looking at the "Record Source" (table or query) based on your form. 2. If your value exist then undo the value and change the form from being data entry then go to the relevant record. Steps CODE [color="blue"]'Your code to look for duplicates in your table or query based on the form [/color] If Duplicates =True Then Me.Undo Me.Form.DataEntry = False [color="green"] 'Change the form back to show all records [/color] [color="blue"] 'Place your code here to go to relevant record on our form[/color] End If Dane |
|
|
|
Jul 5 2007, 10:45 PM
Post
#7
|
|
|
UtterAccess VIP Posts: 12,201 From: Tacoma, WA. |
Dane,
Something like this? Assuming as you suggest the User Is opening a New Blank record Private Sub ChartDate_BeforeUpdate(Cancel As Integer) '********************************* 'Code sample courtesy of srfreeman '********************************* Dim SID As Date Dim stLinkCriteria As String Dim rsc As DAO.Recordset Set rsc = Me.RecordsetClone SID = Me.ChartDate.Value stLinkCriteria = "[chartdate]=" & "#" & SID & "#" 'Check StudentDetails table for duplicate StudentNumber If DCount("chartdate", "tblcharts", stLinkCriteria) > 0 Then 'Undo duplicate entry Me.Undo 'Message box warning of duplication MsgBox "Warning This Chart Date " _ & SID & " has already been entered." _ & vbCr & vbCr & "You will now been taken to the record.", vbInformation _ , "Duplicate Information" 'Go to record of original Chart Date Me.form.dataentry=false rsc.FindFirst stLinkCriteria Me.Bookmark = rsc.Bookmark End If Set rsc = Nothing End Sub |
|
|
|
Jul 5 2007, 10:56 PM
Post
#8
|
|
|
UtterAccess VIP Posts: 12,201 From: Tacoma, WA. |
Jack,
Sorry for the delay Same result using stLinkCriteria = "[chartdate] = #" & SID & "#" Dane explains exactly the whys as I figured it to be, I just can not or have not figured out yet how to code to handle looking for the Duplicate from a New (stand alone) Blank Record. |
|
|
|
Jul 5 2007, 11:07 PM
Post
#9
|
|
|
UtterAccess VIP Posts: 3,071 From: The Land of the Access Ninja's |
Looks good except for the criteria. Jack mentioned it earlier maybe you forgot to include it. Test all aspects and see if it works.
CODE Private Sub ChartDate_BeforeUpdate(Cancel As Integer) '********************************* 'Code sample courtesy of srfreeman '********************************* Dim SID As Date Dim stLinkCriteria As String Dim rsc As DAO.Recordset SID = Me.ChartDate.value [color="red"]stLinkCriteria = "[chartdate] = #" & SID & "#" [/color] 'Check StudentDetails table for duplicate StudentNumber If DCount("chartdate", "tblcharts", stLinkCriteria) > 0 Then Me.Undo 'Undo duplicate entry 'Message box warning of duplication Msgbox "Warning This Chart Date " _ & SID & " has already been entered." _ & vbCr & vbCr & "You will now been taken to the record.", vbInformation _ , "Duplicate Information" 'Go to record of original Chart Date Me.Form.DataEntry = False Set rsc = Me.RecordsetClone rsc.FindFirst stLinkCriteria Me.Bookmark = rsc.Bookmark End If Set rsc = Nothing End Sub I just made some changes,put the Set rsc = Me.RecordsetClone after the Me.form.dataentry Dane Edited by: dallr on Fri Jul 6 0:11:23 EDT 2007. |
|
|
|
Jul 5 2007, 11:26 PM
Post
#10
|
|
|
UtterAccess VIP Posts: 12,201 From: Tacoma, WA. |
Dane,
Works perfectly I really appreciate that ! Thank You |
|
|
|
Jul 5 2007, 11:29 PM
Post
#11
|
|
|
UtterAccess VIP Posts: 3,071 From: The Land of the Access Ninja's |
John, No problem Glad to assist.
Dane |
|
|
|
![]() ![]() |
|
Go to Top · Lo-Fi Version | Time is now: 24th May 2013 - 09:27 PM |