Etxezarreta
Member
- Local time
- Today, 01:42
- Joined
- Apr 13, 2020
- Messages
- 175
Good morning,
Before presenting the problem, here is the context: I select a range of records from one table, "table1, (step1) using a form containing for criteria to filter the records.
Then I would like to transfer those selected records to another, table2 (step2) containing an extra column: a default value ("yes") will be assigned to every record in this last column (step3) This allow me to "mass assign" one value, not going "row to row". If I need to, I will be able to change the value of this last parameter using a form (step4).
Another important information: I will have to migrate the tables to SQL server when I am done with this Acces app.
My problem is:
I have a variable that can be used to "feed" a recordset : str_SQL_finale in the code below.
For stel 2, I guess I could populate the table2 with an update query, but I have problems using it in the Access query builder, since I have a function in str_SQL_finale: Left(t_ListeContacts.[CP],2).
I found interesting ways to do it with recordsets, using a loop or not
(https://stackoverflow.com/questions...rdset-into-existing-access-table-without-loop).
My question is:
What would be a good and strong method to carry it out? Do you have any suggestion please?
Thanks a lot in advance.
str_SQL = "SELECT t_ListeContacts.Nom_contact, t_ListeContacts.Prenon_contact, t_ListeContacts.Nom_structure, t_ListeContacts.Fonction, t_StatutJuridiqueSoignants.StatutJuridiqueSoignant, t_IntitulesProfession.Profession, " & _
"t_Departements.CodeDepartement, t_ListeContacts.Ville FROM (t_StatutJuridiqueSoignants INNER JOIN (t_IntitulesProfession" & _
" INNER JOIN t_ListeContacts ON t_IntitulesProfession.ID_Profession = t_ListeContacts.FK_Profession) ON " & _
"t_StatutJuridiqueSoignants.ID_StatutJuridiqueSoignant = t_ListeContacts.FK_Statut_juridique) INNER JOIN " & _
"t_Departements ON Left(t_ListeContacts.[CP],2)= t_Departements.CodeDepartement"
If (Len(str_CritereDepartement) <> 0) Then
str_SQL1 = str_SQL & " Where t_Departements.CodeDepartement In (" & str_CritereDepartement & ")"
str_SQL_finale = str_SQL1
End If
Debug.Print str_SQL_finale
If (Len(str_CritereProfession) <> 0) Then
str_SQL2 = str_SQL1 & " AND t_IntitulesProfession.Profession IN (" & str_CritereProfession & ")"
str_SQL_finale = str_SQL2
End If
Debug.Print str_SQL_finale
If (Len(str_CritereStatut) <> 0) Then
str_SQL3 = str_SQL2 & " AND t_StatutJuridiqueSoignants.StatutJuridiqueSoignant IN (" & str_CritereStatut & ")"
str_SQL_finale = str_SQL3
End If
Debug.Print str_SQL_finale
Before presenting the problem, here is the context: I select a range of records from one table, "table1, (step1) using a form containing for criteria to filter the records.
Then I would like to transfer those selected records to another, table2 (step2) containing an extra column: a default value ("yes") will be assigned to every record in this last column (step3) This allow me to "mass assign" one value, not going "row to row". If I need to, I will be able to change the value of this last parameter using a form (step4).
Another important information: I will have to migrate the tables to SQL server when I am done with this Acces app.
My problem is:
I have a variable that can be used to "feed" a recordset : str_SQL_finale in the code below.
For stel 2, I guess I could populate the table2 with an update query, but I have problems using it in the Access query builder, since I have a function in str_SQL_finale: Left(t_ListeContacts.[CP],2).
I found interesting ways to do it with recordsets, using a loop or not
(https://stackoverflow.com/questions...rdset-into-existing-access-table-without-loop).
My question is:
What would be a good and strong method to carry it out? Do you have any suggestion please?
Thanks a lot in advance.
str_SQL = "SELECT t_ListeContacts.Nom_contact, t_ListeContacts.Prenon_contact, t_ListeContacts.Nom_structure, t_ListeContacts.Fonction, t_StatutJuridiqueSoignants.StatutJuridiqueSoignant, t_IntitulesProfession.Profession, " & _
"t_Departements.CodeDepartement, t_ListeContacts.Ville FROM (t_StatutJuridiqueSoignants INNER JOIN (t_IntitulesProfession" & _
" INNER JOIN t_ListeContacts ON t_IntitulesProfession.ID_Profession = t_ListeContacts.FK_Profession) ON " & _
"t_StatutJuridiqueSoignants.ID_StatutJuridiqueSoignant = t_ListeContacts.FK_Statut_juridique) INNER JOIN " & _
"t_Departements ON Left(t_ListeContacts.[CP],2)= t_Departements.CodeDepartement"
If (Len(str_CritereDepartement) <> 0) Then
str_SQL1 = str_SQL & " Where t_Departements.CodeDepartement In (" & str_CritereDepartement & ")"
str_SQL_finale = str_SQL1
End If
Debug.Print str_SQL_finale
If (Len(str_CritereProfession) <> 0) Then
str_SQL2 = str_SQL1 & " AND t_IntitulesProfession.Profession IN (" & str_CritereProfession & ")"
str_SQL_finale = str_SQL2
End If
Debug.Print str_SQL_finale
If (Len(str_CritereStatut) <> 0) Then
str_SQL3 = str_SQL2 & " AND t_StatutJuridiqueSoignants.StatutJuridiqueSoignant IN (" & str_CritereStatut & ")"
str_SQL_finale = str_SQL3
End If
Debug.Print str_SQL_finale