1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| ' Solution 1
If Me.Check1 = True Or Me.Check2 = True Then
strSQL = "INSERT INTO table2 ("
strSQL = strSQL & IIf(Me.Check1 = True, "champ1", "")
strSQL = strSQL & IIf(Me.Check2 = True, ",champ2", "") & ")"
strSQL = strSQL & " SELECT "
strSQL = strSQL & IIf(Me.Check1 = True, "table1.champ1", "")
strSQL = strSQL & IIf(Me.Check2 = True, ",table1.champ2", "")
strSQL = strSQL & " FROM table1;"
CurrentDb.Execute strSQL, dbFailOnError
' Solution 2
DoCmd.RunSQL "Insert into table2 (" & (IIf(Me.Check1 = True, "champ1", Null) & IIf(Me.Check2 = True, ", champ2", Null)) & _
") SELECT " & (IIf(Me.Check1 = True, "table1.champ1", Null) & IIf(Me.Check2 = True, ", table1.champ2", Null)) & " from table1;"
End If |
Partager