Mettre à jour plusieurs enregistrements en même temps (sélection dans un sous form)
bonjour à tous,
je souhaite mettre à jour des enregistrements via une combox. Pour cela je souhaite les sélectionner dans le sous formulaire puis assigner la valeur de la combox par clic sur bouton.
Pour un enregistrement sélectionné, mon code fonctionne mais lorsque j'ai plusieurs enregistrements je ne sais pas comment appeler la sélection... J'ai utilisé l'aide access pour mettre en place les fonctions SelTop et SelHeight afin de sélectionner plusieurs enregistrements.
voici mon code sur l'évènement clic du bouton commande :
Code:
1 2 3 4 5 6 7 8 9 10 11 12
| Private Sub cmdSelectedCompanyNames_Click()
Dim combo As String
Dim X
' Restore the lost selection.
SelRestore
' Enumerate the list of selected company names.
X = DisplaySelectedCompanyNames()
combo = Me.choixcontroleur.Value
DoCmd.RunSQL "UPDATE T_dossiers SET [ControleurSecond]= '" & combo & "' WHERE IDdossier=" & Me.recevabilité_formA.Form.IDdossier
End Sub |
je n'ai pas changé les noms utilisés dans l'exemple de microsoft donc ne pas faire atention à cela. je me demande comment mettre à jour X qui représente si je ne me trompe pas la sélection de mon sous form.
Le code doit être modifié au niveau du module ou sur l'évènement click ?
Voici le code du module :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| Option Compare Database
Option Explicit
Dim MySelTop As Long
Dim MySelHeight As Long
Dim MySelForm As Form
Dim fMouseDown As Integer
Function DisplaySelectedCompanyNames()
Dim i As Long
Dim F As Form
Dim RS As Recordset
Dim combo As Long
' Get the form and its recordset.
Set F = Forms![EncoursCtrl_Form]
Set RS = F.RecordsetClone
' Move to the first record in the recordset.
RS.MoveFirst
' Move to the first selected record.
RS.Move F.SelTop - 1
' Enumerate the list of selected records presenting
' the CompanyName field in a message box.
For i = 1 To F.SelHeight
MsgBox RS![Controleur]
RS.MoveNext
Next i
End Function
Function SelRecord(F As Form, MouseEvent As String)
Select Case MouseEvent
Case "Move"
' Store the form and the form's Sel property settings
' in the MySel variables ONLY if mouse down has not
' occurred.
If fMouseDown = True Then Exit Function
Set MySelForm = F
MySelTop = F.SelTop
MySelHeight = F.SelHeight
Case "Down"
' Set flag indicating the mouse button has been pushed.
fMouseDown = True
Case "Up"
' Reset the flag for the next time around.
fMouseDown = False
End Select
End Function
Public Sub SelRestore()
Debug.Print "got into Restore"
' Restore the form's Sel property settings with the values
' stored in the MySel variables.
MySelForm.SelTop = MySelTop
MySelForm.SelHeight = MySelHeight
End Sub |
Si quelqu'un a une idée... (?) merci ;)