I've made a couple of minor changes to your code & tested it with a linked database table.
I've removed specifying the destination table from the procedure declaration
Also removed all [] which you only need if you have spaces in the table names
It works for me - see attached
Code:
Function InitialiserSelection(ByVal strTable As String, _ ByVal strPrimaryKey As String, _
Optional ByVal strTableSelection As String, _
Optional ByVal strWhere As String = "")
' strTableSelection = "[" & strTableSelection & "]" 'NOT NEEDED UNLESS YOU HAVE SPACES
CurrentDb.Execute "DELETE * FROM " & strTableSelection & ";"
Dim strSQL As String
'strSQL = "INSERT INTO " & strTableSelection & " (Numero, Selection)" _
& " SELECT [" & strPrimaryKey & "], False" _
& " FROM [" & strTable & "]"
'None of the [] brackets are needed UNLESS YOU HAVE SPACES
strSQL = "INSERT INTO " & strTableSelection & " (Numero, Selection)" _
& " SELECT " & strPrimaryKey & ", False" _
& " FROM " & strTable & ""
' Debug.Print strSQL
If strWhere <> "" Then strSQL = strSQL & " WHERE " & strWhere
CurrentDb.Execute strSQL
End Function
I've then run this sub from a form button
Code:
Sub TestCode()
InitialiserSelection "Tb7_Projet", "ID", "Tb_Selection"
End Sub