Please Check My Insert Query (avoid Inserting Duplicates)

Nov 28, 2007

I want to insert data into a table where a symbol does not already exist for that date. I am not sure what i am doing anymore :( So please help me verify that this won't insert duplicates? Am i using the correct logic? :confused:

"INSERT INTO StocksData (Symbol, [Security Name], [Market Category], " & _
"[Reg SHO Threshold Flag], FileDate) " & _
"SELECT DISTINCT Symbol, [Security Name], [Market Category], " & _
"[Reg SHO Threshold Flag], '" & fileDate & "'" & _
"FROM " & sTableName & _
" WHERE ((Symbol Not In (select Symbol from StocksData)) AND (" & _
fileDate & " Not In (select FileDate from StocksData)));"

View Replies


ADVERTISEMENT

How To Avoid Duplicates In Append Query

Jun 13, 2005

Hi all,
I have an append query that I run daily and want to append only records with
different OrderID.
------------------------------------------------------------------------
INSERT INTO tblConfirmSchedule ( OrderID, JobCode, JobDate, Status, [Home#],
[Work #], Ext, [Other#], Ext2 )
SELECT Orders.OrderID, [Schedule Info].JobCode, JobSchedule.JobDate,
JobSchedule.Status, CustNew.[Home#], CustNew.[Work #], CustNew.Ext,
CustNew.[Other#], CustNew.Ext2
FROM (CustNew INNER JOIN Orders ON CustNew.CustomerID=Orders.CustomerID)
INNER JOIN ([Schedule Info] INNER JOIN JobSchedule ON [Schedule
Info].JobCode=JobSchedule.Scheduled) ON Orders.OrderID=[Schedule Info].OrderID
WHERE (((JobSchedule.JobDate)>Now()+3) And
((JobSchedule.Status)="Scheduled"));
--------------------------------------------------------------------------

Any ideas?
Thanks in advance,
Emilio

View 1 Replies View Related

Simple Query -- How To Avoid Duplicates?

Nov 28, 2005

2 tables in an Access database
tblPurchases: columns: Index (PK-autonumber)| Store| Product| Cost
data: 1| Staples | Tape | $0.89
2| Staples | Paper | $4.50
3| OfficeMax | Markers | $3.50
4| OfficeMax | Paper | $4.75
5| OfficeMax | Pens | $1.98

tblInfo: columns: Index (PK-autonumber) | Store | Product
The data in the access database tblInfo.Store is queried from tblPurchases.

Here is the query for the rowin my database design view:

SELECT DISTINCT tblPurchases.Index, tblPurchases.Store FROM tblPurchases;

When I am in the database and access the column's pull down, I get ALL records, including duplicates (so OfficeMax is listed 3 times.) How do I get it so I only see
Staples
OfficeMax
in the pull down when in the database?

Thanks!

View 4 Replies View Related

Queries :: INSERT QUERY Not Inserting One Field

Nov 27, 2014

I have a form with many fields and one field has an OnChange event to run an insert query or log an entry in a table about the change. I get insert entry written with everything except one field.The OnChange event code is:

Code:
If AddressStatusFld = 2 Then
'If it has changed from Current to Non-Current create a Contact Log entry for this matte
If (Val([MatterShortNoFld]) Mod 2 = 1) Then
Me.OperatorFld = 16

[code]....

I just can't work out why the record in MatterContactsMade table has a null value for the field Operator.

View 4 Replies View Related

Queries :: Check If Record Exists Before Inserting From Form?

Jul 2, 2014

The problem I have is, that I need to insert an apointment into de database but first I need to verify if there is a record or an apointment in that room that day the same hour, if that is so send a msgbox saying an apointment already exist in that room this day at this hour.

i tried using dlookup but it only works in one record using just one criteria

View 10 Replies View Related

Insert Rows Skip Duplicates

Dec 28, 2006

Hello,

I want to copy data from one table to another:
INSERT INTO Table1 (codeid) SELECT codeid FROM Table2 WHERE a=7

it works, but the problem occurs when diplicate entries occur in codeid of Table1 (because is is set to No Duplicates).

As a result no rows are inserted. It's OK, cause that's the way it should be, but I was wondering if there is a way to tell MS Access to skip insertion of values that will cause duplication. So the rows that are ok will be inserted and the ones that cause duplicates will be skipped.

I just don't want to go through the loop and insert row-by-row.

Thank you.

View 2 Replies View Related

Check For Duplicates

Feb 14, 2006

Hello everyone,
This is code with which I choose records from one table and I put them to another table (OdabranaOprema),
can I add code with which I can stop choosing the same record twice?
I would like in that case have possibility to change the quantity of the record which is selected twice,

thanks

Private Sub cmdOdaberi_Click()

On Error GoTo Handler

Dim strRedak As String
Dim strOdabranaReferenca As String
Dim rsPonudjenaOprema As Recordset
Dim rsOdabranaOprema As Recordset
Dim db As Database
Dim intRedak As Integer
Dim strSQL As String
Dim strSQLOdabir As String


txtNapajanje.SetFocus


Set db = CurrentDb

strSQL = " SELECT Napajanje.Referenca As Referenca, Napajanje.Opis as Opis, Napajanje.Visina " & _
" FROM Napajanje " & _
" WHERE (((Napajanje.PickFlag)= True))"

strSQLOdabir = "Select OdabranaOprema.Referenca, OdabranaOprema.Opis, OdabranaOprema.Kolicina, OdabranaOPrema.Visina " & _
"From OdabranaOprema"

Set rsPonudjenaOprema = db.OpenRecordset(strSQL, dbOpenSnapshot, dbReadOnly)

Set rsOdabranaOprema = db.OpenRecordset(strSQLOdabir)



Do Until rsPonudjenaOprema.EOF

txtNapajanje.SetFocus

rsOdabranaOprema.AddNew
rsOdabranaOprema.Fields("Referenca").Value = rsPonudjenaOprema.Fields("Referenca").Value
rsOdabranaOprema.Fields("Opis").Value = rsPonudjenaOprema.Fields("Opis").Value
rsOdabranaOprema.Fields("Visina").Value = rsPonudjenaOprema.Fields("Visina").Value
rsOdabranaOprema.Fields("Kolicina").Value = txtNapajanje.Value


rsPonudjenaOprema.MoveNext
rsOdabranaOprema.Update

Loop

Set rsPonudjenaOprema = Nothing
Set rsOdabranaOprema = Nothing

Set db = Nothing

Handler:

Izlaz:
End Sub

View 1 Replies View Related

How Can I Check For Duplicates - But Allow Them

Feb 6, 2006

I have a database called "Main" containing customer details and interactions.

One of the fields is the "Customer Number", whilst I know I can index the field to stop duplicates, is there a way to check for duplicates when entering the customer numbers into the form and display a warning message as opposed to just rejecting the entry? There are occassions I need to create multiple entries but would like to be notified.

Here's hoping....:confused:

View 3 Replies View Related

Forms :: Check For Duplicates Based On Name

Aug 7, 2015

I have a form (MemberDetails) and I want it to check if the member I'm adding has already been added, or at least give me a warning that the member might be a duplicate. I have a FName field and LName field that I would like checked (together). I know it's possible because I've seen it done on the Address Book template, but they have it set up to where the First & Last name are saved as one field in another table.

Expression used in the template, here it is.

=IIf(DCount("*","[Contacts Extended]","[ENV_NUM]<>" & Nz([ENV_NUM],0) & " And [Contact Name] = '" & Replace(Nz([Contact Name]),"'","''") & "'")>0,"Possible Duplicate","")

View 14 Replies View Related

Copy Data From One Table To Another & Check For Duplicates

Aug 8, 2005

hi, I have 2 Tables: tablea & tableb. The field names in both tables are: user_id, firstname, lastname, from these i have 2 querys (querya & queryb) both of which just look at the fields from the repective tables, & from this i have 1 form (entry form) that pics up the fields from querya. I would like to be able to enter details (records) into the entry form which puts all the data into tablea then automatically copies all the information into tableb, then automatically checks to make sure there are no duplicate records in tableb and finally deletes all the records out of tablea (probably after the form closes). This might sound a bit strange why i want to do this but I hope if its possible it could be used in a larger database.

I think i need to do querys but not sure what I need to do, Any advise would be very helpful.

View 3 Replies View Related

Forms :: Check For Duplicates In Real Time

Apr 2, 2013

I have a form which im using to store records about companies that I have mailings with. The company name is my unique field as no two companies should have the same name. This form is accessed by several different people and data is input so I dont want duplicates of the company name being produced. Currently, the form wont save a record if it is duplicated but by then I would have filled out the entire form and wasted my time. Is there a way to do the following:

As I enter the company name it would look up exisitng company names. eg if i wanted to enter a new company called 'Dans Plumbing', I would type 'D' and below the text box would display a load of existing records starting with D. after that when I type 'Da' it would only display records starting with Da and so on. All being well, when I have finished typing the company name there should be nothing underneath so that I instantly know its not a duplicate and vice versa.

The possible duplicate doesn't have to be underneath it could auto complete IN the text box a bit like the address bar on a web browser.

View 4 Replies View Related

Modules & VBA :: Check For Duplicates When Importing Multiple Records Into Datasheet View Form

Aug 15, 2014

I am using the following code to check for duplicate tickets when importing multiple records into a datasheet view form by using the paste append function.

Code:
Private Sub Ticket_Number_BeforeUpdate(Cancel As Integer)
DoCmd.SetWarnings False
If DLookup("Ticket_Number", "Record_Store", "Ticket_Number= '" & Me.Ticket_Number.Value & "'") > 0 Then
Cancel = True
MsgBox "There were import errors, please open View Import Errors above."
End If
End Sub

The form is used to insert multiple records into the database at a single time.

That codes works to check for duplicates. And if there are none there are no popup messages.

If there are duplicates though it gives a popup for every single Ticket_Number that is a duplicate.

I am wondering if there is a way for it to give only a single popup once it completes checking all the records to be imported for duplicates.

View 14 Replies View Related

Modules & VBA :: Check Status Of Insert Key (On Or Off) When Form Is Loaded

Sep 12, 2014

is there a way in vba we can check the status of Insert key if it is on or off when the form is loaded?

i want for the insert key to be on, where the key strokes write over the existing entry.

i do set the key preview to "yes" in the form, and it works fine, but i wanted it only on a specific object.

View 2 Replies View Related

Modules & VBA :: Insert Two Values From A Form In Table And Check If They Already Exist

Jan 27, 2015

I'm trying to write some Code with the target to take a value from a textbox (out of a form) and a pregiven value (in this case = 2) and enter them in a new record in a table. But only if there is not already a record with the exact same combination of these to values. When done, the same button should proceed you to the next form (but this code is not already implemented in the fragment below) even if no values are added because they already exist in this combination.

Code:
Public Function GetID_PatientStudiesGroup&()
GetID_PatientStudiesGroup = [Forms]![frm_PatientStudiesGroupTZP]![ID_PatientStudiesGroup]
End Function
Private Sub BPRS_T1_Button_Click()
Call GetID_PatientStudiesGroup&
Dim strSQL As String

[Code] ....

As you can see, I tried to use a function to refer to the value out of the form, because I didn't find out how to refer to a form in an SQL Code.

Just to give you a better overview: The table where the information should be added is named "tbl_PatientStudiesGroupTZP". The form where you find the Textbox "ID_PatientStudiesGroup" (with the value I need to transport) is named "frm_PatientStudiesGroupTZP". Every part (except the WHERE NOT EXISTS part) worked perfectly for itself, but not when thrown together.

View 10 Replies View Related

INSERT Query - Insert New Data Only

Jul 2, 2010

Table TBL_NEWDATA is used to append new data to table TBL_PERSON_ALLOCATIONS.

TBL_NEWDATA { Person_ID, Department_ID }
TBL_PERSON_ALLOCATIONS { Person_ID, Department_ID, ... }

I need to devise a query to append data for a particular Department_ID from TBL_NEWDATA to TBL_PERSON_ALLOCATIONS where that data does not already exist there. i.e. for Department_ID 'Research', I would want to append 'Person_ID', 'Department_ID' (in this case: 'Research') to TBL_PERSON_ALLOCATIONS for any tuples not already held.

INSERT INTO TBL_PERSON_ALLOCATIONS (Person_ID, Department_ID)
SELECT Person_ID, Department_ID
FROM TBL_NEWDATA
WHERE TBL_NEWDATA.Department_ID='Form...'

[code]...

This Query takes a single argument from a control (Forms!Main!IN_Department), and this is the Department_ID to be updated.Is there any way to do this using a single query or will I have to use sub queries? I'd hoped not to as to keep the database as concise as possible.

View 2 Replies View Related

Inserting Name From Listbox Into Query

Nov 8, 2004

I have a listbox inside a subform. I want to use the 'click' Event on a "search" command button (found on the main form) to trigger
a query from inside that listbox and fill it with values from a table. The following is the argument I have written for that event procedure:


Private Sub CommandSearch_Click()
Me.GS_SearchSF.Form.listSF1.RowSource = _
"SELECT MaxSize1 " & _
"FROM GS_Ctg_Float " & _
"WHERE Supplier = '" & Me.GS_SearchSF.Form.SupplierQuery.Value & "';" 'THIS ONE ISN'T WORKING
End Sub


Except as you might imagine, it is not working. It works when I just type a name from that table into the argument in place of
the text seen above in red. For instance:

Private Sub CommandSearch_Click()
Me.GS_SearchSF.Form.listSF1.RowSource = _
"SELECT MaxSize1 " & _
"FROM GS_Ctg_Float " & _
"WHERE Supplier = 'Viracon';" 'THIS ONE WORKS
End Sub

What am i doing wrong?

Here's some background:

GS_SearchSF is the name of my subform

listSF1 is the name of the list box in the SubForm that the
query is supposed to fill

SupplierQuery is the name of the list box in the subform
I want to extract the value from and put into the query

View 8 Replies View Related

Find Duplicates And Create Table With Dates Of Duplicates

Feb 12, 2008

Hi this is my first post... so hi all :)

ok what i have is a table with contact details 900k plus

there are about 90k of which are duplicates.

this is the basic feilds that are important in this case.

Id, data_source, data_recived, data_code,

what i want is to have a table with unique records (no dups in data_code)

this table will look like this...

Id, data_code, Num_dups, dup1_source, dup1_date, daysbtw_Dup1_dup2, dup2_source, dup2_date, daysbtw_Dup2_dup3 ,dup3_source, dup3_date, daysbtw_Dup3_dup4 ,dup4_source, dup4_date,

I know there is no more than 4 dups of each record.

what i want from this is a table that will give me a record of how many dups for each record then all the dates that they were added and the date between each record entry.

if anyone can help it would be great .

thanks in advance.

View 6 Replies View Related

Doing Calculation And Inserting That Value Into New Row Into Query Table

Apr 13, 2008

Hi, I am wondering If I can Sum the value of rows in one field of my Query Table and Inserting that Calculated value into the bottom of the summed Row in the VBA or through Query Design View.

Please let me know, Thank YOU!

Below I have attached the picture of the data that Im trying to sum and insert into a new row that Hopefully can be created through MS access Query.

View 1 Replies View Related

Inserting Data Into A Field From A Query.

Oct 3, 2004

Hi,
Am currently working on a project for AS IT. one problem that i need to come across is trying to see data in a field that comes from a query?!?! Confused?! so am i!

When i first open the form, a paremeter query appears asking me to insert a surname (which i have created) when i insert the surname....and click on the drop down button, it gives me three values...ForeName, Surname and class

When clicking on the pupils name, i want the Class of the student to be inserted into the Class Field!

Can anybody help?
Danbwest

View 1 Replies View Related

Queries :: Inserting With Duplicate Key Query

May 19, 2013

I have a load of data in an excel spread sheet that I'm trying to put into an access using Excel VBA (Jet/ACE SQL I think!?). I do this by constructing INSERT INTO strings and looping through my spread sheet. Let's say the primary key is associated with the field [Company] which holds the company names. A simplified version of what I was using (it all works great ) is below:

Code:
Set rs = New ADODB.Recordset
Set cn = New ADODB.Connection
cn.ConnectionString = GetConnectionString()
cn.Open
cn.Execute strSQL

where strSQL =

Code:
INSERT INTO tblTestMDB ([Company], [Date])
VALUES ('BP', '30/09/2012')

Unfortunately, I am having issues with users adding the same company twice. I'd like it to:

- update the existing company info if the company already exists
- add the company if it is not already there.

I'm trying to do it in two stages. First an update, then an add. The first part works great :

Code:
UPDATE tblTestMDB
SET [Date]='21/03/2015'
WHERE [Company]='BP';

The second part: (I have tried numerous variations on the syntax):

Code:
INSERT INTO tblTestMDB ([Company], [Date])
VALUES ('BP', '30/09/2012')
WHERE NOT EXISTS (SELECT * FROM tblTestMDB WHERE [Company] = 'BP');

I find the error messages rather cryptic but they include things like "Query input must contain at least one table or query." or "Missing semicolon ( ; ) at end of SQL statement." (<== No I'm not!?

View 2 Replies View Related

Queries :: Query For Inserting Random Records Into Temporary Table

Jul 16, 2015

I'm trying to insert 10% of a dataset from dbo_billing into another table Random_Temp. Another form is open when this query is to be ran that passess in the billyear and billmonth... I'm sure it's a syntax issue as I can isolate the random number part and it displays the appropriate data, I just can't re-write it to insert into the other table:

INSERT INTO Random_Temp ( indx, peopleId, audited )
SELECT TOP 10 PERCENT b.indx, b.peopleId, b.audited
FROM dbo_Billing AS b
WHERE (((b.billYear)=[Forms]![billing]![billyear]) AND ((b.billMonth)=[Forms]![billing]![billmonth]) AND ((b.recertifying)=-1))
ORDER BY Rnd(-(1000*b.indx)*Time());

View 2 Replies View Related

Modules & VBA :: Inserting From Excel Number Of Query Values And Destination Fields Not Same

Jan 3, 2014

I am just beginning to manipulate Access from Excel.

I am trying to insert a row into a table. I am adding values for every field (8) except an Autonumber.

I have 2 Insert strings which are identical except for the fact that the one that doesn't work, doesn't specify which fields I am entering data into, which I presume shouldn't be necessary in this case.

When I try to use the second version I receive the error message...

Number of Query Values and Destination Fields are not the same.

The string that works perfectly is:-

Code:

strSQL = "INSERT INTO Clubs (ClubNumber,ClubName,ClubGrade,ClubRegion,ClubPosition,ClubHasHistory,clubinleague,cluboriginalposition) VALUES (" & clubCount + 1 & ",'" & lstrNewClubName & "'," & lintNewClubGrade & "," & lintRegion & "," & 0 & "," & vbFalse & ",'" & lstrNo & "'," & 10 & " )"

The one that generates the error message, which is identical except that I have removed the list of fields is:-

Code:

strSQL = "INSERT INTO Clubs VALUES (" & clubCount + 1 & ",'" & lstrNewClubName & "'," & lintNewClubGrade & "," & lintRegion & "," & 0 & "," & vbFalse & ",'" & lstrNo & "'," & 10 & " )"

The execute command is:-

Code:

gcnConnection.Execute strSQL, , adCmdText + adExecuteNoRecords

View 1 Replies View Related

Find Duplicates Different Than Duplicates Deleted

Dec 8, 2005

Hey, all! Thanks for helping, here is my situation.

I have a table with about 70,000 records that have duplicate Address field values. The rest of the field values for those records are different. When I do a find duplicate querry I get the result that 17,000 records have the same address. However, when I do the append qurrey as instructed here: http://support.microsoft.com/?kbid=209183 I get a total of only 600 records in the new table. I have tried deleting all of the indexes for both the new and old table, with no luck.

I'm using Access 2000 on XP Pro.

If anyone could help with this I would greatly appreciate it!

Thanks

Will

View 14 Replies View Related

Query Help, Duplicates

Aug 23, 2005

I have a table in a healthcare patient database that stores Admitting Number, Scan Number, Last Name, and some other fields detailing the scan. Each patient can have multiple scans and I'm trying to design a query that lists how many scans each patient has had by finding all the duplicate admitting numbers. I'm using this SQL statement:

SELECT MultScans.Admitting_Number, Count(MultScans.Admitting_Number) AS Num_Of_Scans
FROM MultScans
GROUP BY MultScans.Admitting_Number
HAVING (((Count(MultScans.Admitting_Number))>1));

which works fine but I can't figure out how to also print out the last name, scan number and the other fields in this query. If I add the field to the select part it says I can't because the expression is not part of the aggregate function and if I add the expression to the 'group by' the query runs but displays all the duplicates. Thanks for any help.

View 3 Replies View Related

Please Help With This Query On Duplicates

Apr 4, 2006

Please help. I am having difficulty understanding why a subform is showing duplicates despite using SELECT DISTINCT for its query. I have looked all over the forum but am still quite confused.

I think my database is normalised but this may be the problem and can attach it if necessary.

My query is as follows

SELECT DISTINCT StudentAndCourse.ClassID, StudentAndCourse.LevelID, StudentAndCourse.StudentID
FROM [Level] INNER JOIN (Class INNER JOIN StudentAndCourse ON Class.ClassID=StudentAndCourse.ClassID) ON Level.LevelID=StudentAndCourse.LevelID;


Any help would be most appreciated as I cannot understand what is going wrong.

View 1 Replies View Related

Query Without Duplicates

May 1, 2007

Hello,
I am just wondering whether there is any way I could run a simple query that would pull all the data I need and inform me of the duplicates if there is any.

Thanks!

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved