Records in subform duplicated itself

shafara7

Registered User.
Local time
Today, 08:11
Joined
May 8, 2017
Messages
118
I have a form with a subform on it.
Recently I added a new table in my subform query because it needs to update the record in one of this particular field when it is edited.

For some records, when it is edited, no duplication occured.
And some, when that particular field is edited, it automatically makes a duplicate.
Some records were duplicated 5 times, some 17 times and some 24 times.

There is a combobox that is already there for a long time and it will filter the subform according to the measuring equipment group.
So I just added the code (in Bold) so that it is compatible with the new query that I have added.
Code:
Private Sub cboGruppe_AfterUpdate()
    sfmMessung.Form.RecordSource = "SELECT tblMessauftrag.*, tblFOLand.txtLand, tblBauphasen.txtBauphase, 
tblPulk.txtBezeichnung, tblMessaufgaben.txtMessaufgabe, 
tblPrioritaet.txtBezeichnung, 
qryStammdatenBelegung.*, 
[txtFahrzeugtyp] & ' - ' & [qryStammdatenBelegung].[txtBezeichnung] AS Ausdr1,
 qryBelegungPerson.tblMesstechniker.txtAnzeige, 
qryBelegungPerson.tblBemusterer.txtAnzeige, [B][COLOR="Red"]
IIf(IsNull([indAbweichendeMessanlage]),[tblMesstechniker].[txtAnzeige],[qryMessauftragPerson].[txtAnzeige]) AS Ausdr2  [/COLOR][/B]" & _

"FROM (tblMessanlage 
[B][COLOR="red"]LEFT JOIN qryMessauftragPerson 
ON tblMessanlage.ID = qryMessauftragPerson.ID[/COLOR][/B]) 
RIGHT JOIN (tblMessaufgaben 
RIGHT JOIN (tblFOLand 
INNER JOIN (tblPrioritaet RIGHT JOIN (tblPulk 
RIGHT JOIN ((tblBauphasen 
RIGHT JOIN (qryStammdatenBelegung 
INNER JOIN tblMessauftrag 
ON (qryStammdatenBelegung.indFOLand = tblMessauftrag.indFOLand) 
AND (qryStammdatenBelegung.txtTeilesachnummer = tblMessauftrag.txtTeilesachnummer)) 
ON tblBauphasen.lngReihenfolge = tblMessauftrag.indBauphase) 
INNER JOIN qryBelegungPerson 
ON (tblMessauftrag.indFOLand = qryBelegungPerson.indFOLand) 
AND (tblMessauftrag.txtTeilesachnummer = qryBelegungPerson.txtTeilesachnummer)) 
ON tblPulk.ID = tblMessauftrag.indPulk) 
ON tblPrioritaet.ID = tblMessauftrag.indPrioritaet) 
ON tblFOLand.ID = tblMessauftrag.indFOLand) 
ON tblMessaufgaben.ID = tblMessauftrag.indMessaufgabe) 
ON tblMessanlage.ID = tblMessauftrag.indAbweichendeMessanlage " & _

"WHERE (Not tblMessauftrag.datEinarbeitIst Is Null Or Not tblMessauftrag.datMessungSoll Is Null) 
And (tblMessauftrag.datMessungIst Is Null) " 
& IIf(cboGruppe.value <> 0, "
AND (IIf([tblMessanlage].[lngGruppe] Is Null,
 [qrystammdatenbelegung].[lngGruppe],
 [tblMessanlage].[lngGruppe]) = " & cboGruppe.value & ") ", "") & _
 
"ORDER BY tblMessauftrag.lngMessauftragNr;"
End Sub

I don't know whether the codes are wrong or maybe there's something wrong with the query.
See screenshots for reference.
In photo Query Form Messung-4, the blue box indicate no duplication and red box are duplicates.
 

Attachments

  • Form Messung.jpg
    Form Messung.jpg
    101.8 KB · Views: 370
  • Query Form Messung-1.jpg
    Query Form Messung-1.jpg
    103.6 KB · Views: 180
  • Query Form Messung-4.jpg
    Query Form Messung-4.jpg
    99.8 KB · Views: 369
it is usually due to one of your tables/queries having multiple foreign keys - suggest check qryMessauftragPerson to see if this is the case
 
Thank you for the reply. Okay but what should I be looking for at the query?
 
Oh my, I have checked it and it does have multiple names for one person.
How do I make it only appear once in the subform?
I mean the name should only came out according to lngMessauftragNr.
If you see in the photo, the field lngMessauftragNr is different.
 

Attachments

  • qryMessauftragPerson.PNG
    qryMessauftragPerson.PNG
    25.6 KB · Views: 248
Found the solution!
In the form query at the properties section, just set Duplicate to No.
A word 'DISTINCT' will automatically be added next to 'SELECT' in the sql. That's all.
 

Users who are viewing this thread

Back
Top Bottom