Forms :: Finding Duplicates - DCount Not Providing Expected Results
Mar 8, 2013
I've been working on trying to get this code to work as expected for days. I'm trying to find duplicates (I can't use primary keys or indexes alone to weed out duplicates due to the structure of the tables involved) in a subform as a user enters data. As soon as a project number is added, the code is supposed to count the number of records that contain that particular project number as well as a category number (there can be multiples of the same project numbers as long as their category numbers are different). This is the code I am using in the "Before Update" event of the field in the subform:
Private Sub ProjectID_BeforeUpdate(Cancel As Integer)
Dim strCriteria As String
Dim RecCount As Integer
strCriteria = "([ProjectID] = " & Me.ProjectID & ") AND ([CatID] = " & Me.CatID & ")"
RecCount = DCount("[ProjHrsID]", "tblProjHrs", strCriteria)
[Code] .....
What could I be doing wrong? Nothing about this code seems to work properly - even the Undo and Cancel=True is a problem (I get the "No current record" error).
View Replies
ADVERTISEMENT
Mar 2, 2007
Hi all:
running access 2000. I have a query that I selected to return the Top 1 record sorted descending on the date so it would pick the most recent entry. I did it by selecting Top 5 from the drop down box in query design mode and then changed the 5 to a 1 using SQL View from qry design.
SELECT TOP 1 Class.CourseID, User.UserName, Class.TrainerID, Class.ClassLocationID, Class.ElapsedTime, Class.ClassDate, Class.Comments
FROM [User] INNER JOIN Class ON User.UserID = Class.UserID
ORDER BY Class.ClassDate DESC;
It still gives me as many records as are entered on the system. How can I get JUST the most recent record entry?
thanks:confused:
View 3 Replies
View Related
Sep 11, 2013
My DCount statement is not finding a record that I know is there.
Code:
Private Sub Transfer_WN_Books_Click()
Dim ST As String
ST = "H"
If DCount("*", "Books", Author = " & Me!AuthorID & " And StatFlag = " & ST & ") > 0 Then
DoCmd.Beep
End If
End Sub
It never beeps!
View 10 Replies
View Related
Oct 9, 2004
Hi
I am trying to check for duplication with three fields while entering data.
I have set up a query on the recordsource query and dcount the records
this works in the before update code initially but when editing the record in any field
and moving off the record, I am incorrectly told my once correct entry is now a duplicate.
as though the record compares itself with itself.
ONly if I return its value to empty, move off the record and then reenter the field does it accept it as not duplicated
I'm confused and a little desperate.
thanks
View 9 Replies
View Related
Sep 10, 2013
It is basically a DCount, and it should find records, but returns 0 all the time. My code is:
Code:
Function cntkit(sftd As Date, sftn As String, typid As Integer, specpaint As Boolean) As Integer 'Counts jobs kitted during shift given by sftd and sftn
Dim timeformat As String
timeformat = "#mm/dd/yyyy hh:nn:ss#" 'need this, to convert it to US datetime format
cntkit = DCount("[JOB]", "Archive", "[Type] =" & typid & " And [Autfinish]=False And [SpecPaint] =" & specpaint & " And ([Kit] BETWEEN " & Format(sftstart(sftd, sftn), timeformat) & " AND " & Format(sftstart(sftd, sftn), timeformat) & ")")
End Function
sftstart and sftend are functions which are returning dates. The funcion works fine if I omit the Between part of the criteria. So the problem is in that part.
View 5 Replies
View Related
Oct 15, 2013
I am trying to put in a control measure which won't allow the user to accidentally add a client to areferral more than once. The simplified relationship structure reads:
tblClient 1-------n tblClientReferral n---------1 tblReferral
I am as a far as using a dlookup which correctly gives the error message, but only if it is the first client added to the tblClientReferral table. If the hypothetical situation arises in which the user adds a client, then adds a second client to the referral and accidentally adds the second clientn twice, the Dlookup is not picking this up.
I suppose the solution is using a dlookup which has the criteria saying if the referralID = 'this' AND the clientID = 'this' Then 'do this'. But as far as I am aware you cannt use AND in the criteria?? atleast, it hasn't worked when I tried. A snippet of the vba code used is below:
Dim objClient As Object
Set objClient = Forms![frmAddClient]![cboClientID]
If (DLookup("clientID", "tblClientReferral", _
"referralID = Forms![frmReferral]![referralID]")) = objClient Then
MsgBox "Client already added"
GoTo ExitSub
Else
View 5 Replies
View Related
Nov 1, 2006
Hi
Is there a way of finding duplicate field entries in a table and a query: e.g.
In the Sickness Query (which contains, say 10 fields), in the Section field, it says "Benefits", and in the Week Commening field, it says "15/10/06"
And then
In the Nil Return Table (which only contains the Section & Week commencing fields), they also say "Benefits" and "15/10/06"
If there is a way of finding them, how do I delete the entry that has been made in the Nil return table?
Thanks
Maria
View 4 Replies
View Related
Aug 29, 2006
Hi, been searching this forum for a couple of months now im working with access and up till now i have solved most of my problems:D
Ok the problem.
For the purpose of the question I have a training database:
running one table with user id and user name.
another for job id and job name.
Another for training table with an autonumber, user id, job id, and date
Id like to build a query which bought up the newest only for each user id and job id.
eg.
UI JI Date
2 5 01/05/05
2 5 01/05/06
3 5 01/05/05
3 6 01/05/05
4 6 01/05/06
to
UI JI Date
2 5 01/05/06
3 5 01/05/05
3 6 01/05/05
4 6 01/05/06
Iv tried using a few different ways of using duplicate queryies etc, but im just too newb to figure it out :(
Any suggestions or help would be appreciated.
Thanks
View 3 Replies
View Related
Jan 21, 2005
I have a Lost and Found Database that I enter information in usually every day.
Lots of items like gloves and glasses are entered into the item/s description field as
name of item then color or some other descriptive.
How do you make the combo box bring up all of the items that are related so that I can
pick from a tighter list? Right now when I click on the combobox for say, gloves, it will
bring up only one record of gloves and then I have to scroll through the entire
database to find the right record.
Table Properties
Lost and Found ITEM/S DESC Field:
Field Size - 50
Required - Yes
Allow Zero Length - No
Indexed - No
Unicode Compression - Yes
Form Combo Box After Update [Event Procedure]
Private Sub Combo22_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[ITEM/S DESC:] = '" & Me![Combo22] & "'"
Me.Bookmark = rs.Bookmark
End Sub
View 4 Replies
View Related
May 16, 2005
Sorry for the question's wording.
Here is what bugs me:
- I have one table tblRefctc with the followings fields :
LCtcRef,../..,LRefServ0, LrefServ1,..LrefServ16.
Where all those Lref are long; LCtcRef being the primary key. This table describe a contact from different branches (account, etc..) so while each branch has the relevant information about this contact, they know that that branch too is in contact with the same person.
- I have this other table with describes Events, TblIdxEvt (meeting, whatever) :
LRefidx,IdxEvt,IdxCtc
where IdxCtc is filled with LCtcRef once an event is created.
What I must check for is : For the same IdxEvt, should another branch makes an appointement for LCtcRef (i), I must check if one of the LRefServ0 to LRefServ16 are not already added in the event table.
At this time, I am stuck with making functions which test the existence of the LRefServ(i) (i ranging from 0 to 16) in tblIdxEvt, but I wonder if there is a simpler way to do it with SQL (which, as you could guess, Im not good at).
Thanks in advance for any pointers.
View 2 Replies
View Related
Apr 2, 2014
I need to create a query that will pull duplicate names out of my db.
I would like it to pull all names that have:
duplicate LastName and duplicates of the first 3 letters of the FirstName.
For example, if I had the names:
Bland, Abe
Brown, Abe
Brown, Bill
Buster, Jon
Buster, Jonathon
I would like my query to return only Buster, Jon and Buster, Jonathon.
View 4 Replies
View Related
Dec 13, 2007
Hello,
I am just starting Access...
Or at least trying to learn it on a small project, and I need a jumpstart, if someone woild be so kind and help me out.
I need to organize my e-mail sendings.
In one table (Table Sent) I have e-mail addresses where I have already sent messages.
In an other (Table New) I have some other e-mail addresses, I am preparing to send out.
To make sure to not send mail to those who already got one, I need to compare the two tables, and delete from the Table New those addresses which are already present in Table Sent.
I guess that would be a 2-3 line SQL script...
All of my attempts so far produced no results
Any guidance would be great!
Thanks
Attila
View 14 Replies
View Related
Jun 13, 2013
I am using Access 2010 32-bit on a Windows 7 64-bit platform.I have a database that I have imported existing data into. For the most part, I have eliminated duplicate entries in my Item Number field.
Obviously I have missed at least one (or possibly more) duplicates. When I try to create a NO DUPLICATES index, I am informed that there are duplicate entries.I am looking for a quick way to generate a list of values that are duplicated so I can address those and correct them.Item number field is a number field of type DOUBLE with 2 decimal places.
View 2 Replies
View Related
May 2, 2014
I've been looking everywhere to find a better way of finding duplicates in a table and then recording and adding another value in that record together.
Let me try to explain better.
example:
I have a table that has 2 columns "Name", "DOB". I would like to find all duplicate "DOB" and add all of the "Name"'s together.
Quote:
Name DOB
bob 19800201
Sam 19761211
Jim 19800201
The output I would like is to have Name = bob & Jim DOB = 19800201.
I've tried using the find duplicate wizard in access but I can't seem to group them together and just to find the duplicates it takes upwards of a minute.
View 1 Replies
View Related
Jun 14, 2006
Hi Folks,
I have answered my own question so I thought I would share as I couldn't find the solution in any posts. I confess that I don't understand why my results were wrong, but I managed to get them right. :rolleyes:
When using Dcount in a query, I was getting results which did not match the query results. For instance:
Phase_2: DCount("Project_Phase_ID","tbl_Prj_Details","Project_Phase_ID = 2")
gave an answer of 27 when there were in fact 41 projects in that phase.
Searching the forum I came accross this:
Count() always counts the entire domain.
So, Dcount is not counting the record set of my query but something else. I have 4 tables in the query and no idea what domain my dcount was looking at. I presume the various join types were messing with it somehow. :confused:
To get round this, I stripped out the Dcount expressions and changed the query to a make table. I then used the created table as the basis of a query in which I had my Dcounts. The dcount results now agree with the query recordset. :) :) :)
Any background on the bits I clearly don't understand will be gratefully received. I hope this helps someone else sometime.
Kind regards,
Keith.
View 3 Replies
View Related
Aug 3, 2006
Another question on how might be the best way to do things with dates ?
I have a simple database which is a fault database.
I get an email request to investigate something and I log it and give it a ticket number. If I email back , I put the comments that I sent in the email in the update field on the database.
When I create the ticket its in an open state with a date and time stamp of now()
When I close (drop down box with open and close as options) the ticket it automatically updates the time in the closed filed to Now()
What I want to do is when I updated my comments field , this sets a date value in a hidden field on the form of Now()
So then I need an expression that looks at the difference between the updated time and the now time
i.e. I update a call on 29/7/2006 at 10:00 am
Its now 30/7/2006 at 10:01
i.e 24hrs and 1 minute later
As its more than 24hrs this flags and output to a filed e.g. 1
I then total all the "1" and therefore I have a ticket count of how many calls have not been updated in 24hrs.
So Im assuming I will need an after update event on my comments field put today's date in this hidden field ,and then maybe some sort of code which is maybe on my switchboard which looks at the difference of these dates and if greater than (or equal too) 24hrs it will output a value of 1.
And If I can do this I can also have a flag if its more than 2 days , then clear the 24hr flag an increment a 24hr flag etc.
My tickets should all be closed with 24 hrs , so this is something to capture anything that is open and hasn't been updated in 24hrs
Id appreciate some guidance on the best way to do this ?
Cheers
Jimmy
View 4 Replies
View Related
Mar 27, 2006
I have a query that selects from a table base on 3 entries (Name, BeginDate and EndDate) and should show me 12 other columns and their entries... I have 9 entries for a particular Name, but when i run the query i get 15 results. Some are duplicated but others are not and I don't know where to begin narrrowing it down. Any ideas where to start?
View 2 Replies
View Related
Jan 22, 2008
Now that i have read this again, i think it could be summed up into one question...if i have a form based off a query with an outer join that has various duplicate records, is there a way to use the recordset in an if statement that says something like if this recordID = that recordID then dont show one of them...hence not showing the duplicate field data in the form.If you want a more specific description of the problem, read on, otherwise don't read on.Hi All,So I hope I can explain this ok....here goes....I have a search using dynamic queries: I have a form where the user can put in various information he wants to search to find a record. In this case it is searching for Hotels. So the user can search a country to see all of the hotels in that country. Also, the user can search an interest like Beach or Nature to see those hotels that apply. Obviously each hotel may have more than one interest so I have a 1-many relationship with a table called Hotels_Interests.The kicker, and you can likely already see why, is that the user does not have to fill out every search field. He may search Country&Interest, or just one or the other, or leave everything blank to see all hotels in the database. The results are simply ordered by HotelID or something like that in a form that is based off the dynamic query. The dynamic query is of course just based off the query i explained, but with criteria added in.The problem is with the query that i am basing this search off of. Right now it has the main Hotels table as well as the 1-Many table Hotels_Interests and even another that is 1-Many Hotels_HotelTypes (say All Inclusive, Resort, etc.). So this query has various 1-Many tables as well as the main Hotels. Now, if i fill in all of those fields in the search form, there will obviously not be any duplicates returned, which is super. But if i leave Hotel_HotelTypes search field blank, i will be returned with the same hotel twice or more times, which is my problem, because i want nice search results.I have heard of people using Union queries to get rid of duplicates but this obviously does not solve my problem as i do not want to just get rid of these entries. What i think i want is some VBA method or whatever of showing in my search results each HotelID that meets the search criteria only one time.Right now i have it working with If statements that say if the user has left a specific search criteria blank then base the search off a different query. This is obviously crazy and is only a temp fix. Now that i want three or more 1-many tables in my query, i would be talking about if statements for like 6 or more queries, insane.I apologize for the length of this, but i wanted to be perfectly clear. I feel like it should be not too hard, like using a record set for the form and not showing certain records or something, but i am not sure how to do it.Thanks so much. Dillon
View 4 Replies
View Related
Feb 11, 2014
I am trying to write following code, I want Msg to pop, when all three condition are true, but it not working
'''Non Budgeted Projects need Explanation and Variance class"
If Me.ID.Value >= 90000 And and Me.Variance_Class = "" and Me.Comments_Explanation_Delta_____100K = "" Then
MsgBox "This project is Unbudgeted. Please Add 'Variance Class' and provide Explanation why this project is Unbudgeted project has been added.", vbExclamation, "Rules Checker..."
CheckRules = False
GoTo Exit_CheckRules
View 14 Replies
View Related
Jan 15, 2015
Following concerns about someone accidentally deleting the access database we have been using to crunch performance numbers, I have successfully moved the data on to an SQL server
While the database works as it is, several of the queries are running extremely slow. I therefore decided to see if a stored procedure could run the number crunching on the server instead of passing the data back and forth all the time.
I have taken the series of queries and converted them into a stored procedure that runs too fast for me to blink while giving the same results as before.
The problem I face is that I can trigger the stored procedure from the server management studio manually while supplying the variables needed thus providing the data I need to export to excel in a table for this purpose.
What I want to do is to have a form in access supply the chosen variables (like I could before) and run the stored procedure at the click of a button as part of a series of other queries.
I have looked at pass-through queries but apparently they do not take kindly to variables unless they are hardcoded. The other solution would be to trigger it from VBA but I have not been able to find a solution I could get to work.
How to run a stored procedure on an SQL server from access while also giving it the variables it needs?
Stored procedure name: spNearMissCalculation
Variables:
@SelectedDate (date format) (taken from a form field)
@SelectedVessel (nvarchar(max) format) (taken from a form field)
@SelectedVesselGroup (nvarchar(max) format) (taken from a form field)
View 4 Replies
View Related
May 31, 2014
How can I prevent duplicate records from being added from a form, the dcount in the text field property, trigged before update is where this should be used is what I know but having trouble with the syntax.
I've got the table tblInvnetoryDetail with InvID(AutoNumber), and SerialNumber. The form text field is txtSerialNumber. I've managed this far with the expression
DCount([InvID],"tblinventoryDetail","[txtSerialNumber]=&"'") but this did not work.
How can I get the expression to avoid duplicates.
View 4 Replies
View Related
Aug 4, 2005
Hi All,
basically i'm new to access, i am not a programmer and have been asked (told) to do an access (a few) for our office,
OK what I have is a very very simple database, we add in the post that we post out every day. I have two fields called Postage Paid and Stamp Required. I have used a Dcount to count how many have Postage Paid and how many require a stamp (Stamp Required).
What I want is to add the totals for the day that i enter them, i don't need to store that data, just to tally up the totals for the day i enter them...
View 1 Replies
View Related
Dec 7, 2014
In my form, i would like to sum and dispay the values of datas from two different tables.
Table1: MasterTable1
Table2: MasterTable2
I use the below code for one table and its working.
Text15 = DCount("[client]", "[MasterTable1]", "[Confirmed]=Yes and [Assigned]=No")
But i want to sum the same criteria from MAstertable1 & Mastertable2 and display the data.
View 2 Replies
View Related
Dec 4, 2014
I have a form with a text box "txtSdate" and a text box "txtEdat" and a text box "txttotal". I have a table that is called "Call Logs" and a field in it called "Date" which is shown as mm/dd/yyyy for each record.What i want to do is have "txttotal" display the # of records for the specific date range when the user enters it into "txtSdate" and "txtEdate".
View 8 Replies
View Related
Apr 12, 2013
I think I read somewhere that DCount will not count blank cells, but when I try to do it - it counts everything.
Here is my formula:
=DCount("[E-Mail]","Detail","Not IsNull([E-Mail])" & " AND [Primary] = [Products]![Product Code]")
Basically, I want to count the number of email addresses in the E-Mail column of my Detail table IF the Primary column (also in the Detail table) equals the product code on my form AND if there is something in the E-Mail column for that line. When I did the above formula - and I've done a bunch of different variations - it keeps counting all lines that match the product code.
View 3 Replies
View Related
May 31, 2015
My mainform is "CourseDays" and subform is "CoursesSubForm". The "CoursesSubForm" data source is a table "Courses" which contains a field "Subject".
I add a calculated field on the mainform to count the number of records in the subform. This is my code:
=DCount(”[Subject]”,”[CoursesSubForm]”)
An error message results.
View 5 Replies
View Related