Hello,
I'm running the following queries to concatenate values from a table. The query is working fine, however, sometime it returns duplicate values that I would like to remove. I've tried using "select distinct" with SQL statement but it gave me an error. Could someone please suggest how to remove duplicate values from the "amplicons" field, preferably in the existing code below. Here is an example of the output:
Here is the code:
Thanks,
Mila
I'm running the following queries to concatenate values from a table. The query is working fine, however, sometime it returns duplicate values that I would like to remove. I've tried using "select distinct" with SQL statement but it gave me an error. Could someone please suggest how to remove duplicate values from the "amplicons" field, preferably in the existing code below. Here is an example of the output:
Code:
AKT1 exon (3), ALK exon (25), ALK exon (25), ALK exon (23), ALK exon (22), ALK exon (21), AR exon (6), AR exon (8), BRAF exon (11), BRAF exon (11), CDK4 exon (2)
Here is the code:
Code:
Dim rsI As DAO.Recordset
Dim rsO As DAO.Recordset
Dim rsU As DAO.Recordset
Dim SQL As String
' init table
Set rsI = CurrentDb.OpenRecordset("Select Distinct sample_id from tbl_Samples Where run_name = '" & Me.run_name & "'")
Debug.Print Me.run_name
Set rsO = CurrentDb.OpenRecordset("tbl_failed_amps_report")
While Not rsI.EOF
rsO.AddNew
rsO!sample_id = rsI!sample_id
SQL = "SELECT [tbl_failed_amplicons].[gene] & ' exon (' & [tbl_failed_amplicons].[Exon] & ')' AS expr"
SQL = SQL & " FROM tbl_Samples INNER JOIN tbl_failed_amplicons ON tbl_Samples.sample_id = tbl_failed_amplicons.sample_id"
SQL = SQL & " WHERE (((IIf([gene_panel]<>'Whole Panel',InStr([gene_panel],[gene])>0,' '))=True) AND ((tbl_failed_amplicons.sample_id)= '" & rsI!sample_id & "'))"
Set rsU = CurrentDb.OpenRecordset(SQL)
While Not rsU.EOF
If IsNull(rsU![Expr]) = False Then
rsO!amplicons = rsO!amplicons & ", " & rsU![Expr]
End If
'Debug.Print rsO!amplicons
rsU.MoveNext
Wend
' remove leading ", "
rsO!amplicons = Mid(rsO!amplicons, 3)
rsO.Update
rsI.MoveNext
Wend
Thanks,
Mila