Checkbox dans base de données ACCESS

julia Namor Messages postés 524 Date d'inscription jeudi 27 mars 2014 Statut Membre Dernière intervention 13 janvier 2024 - Modifié le 12 nov. 2018 à 17:11
vb95 Messages postés 3472 Date d'inscription samedi 11 janvier 2014 Statut Contributeur Dernière intervention 13 avril 2024 - 18 nov. 2018 à 19:30
Bonjour
Pour le remplissage d'une base de données access , j'utilise un formulaire avec des textbox , combobox et checkbox. La base access " STOCKAGE" est bien remplie avec les contenus des textbox et combobox mais je bloque sur les checkbox. J'ai beau cocher ces checkbox ; il ne sont pas cochés dans la base . A savoir que j'ai créé les champs B1,B2,B3,B4,B5 "case a cocher dans la base access."
Pourriez vous me détecter mes erreurs?
merci d'avance

Private Sub ENREGISTRER()
        ' ADD PARAMETERS
        Access.AddParam("@NOM", NOM.Text)
        Access.AddParam("@PRENOM", PRENOM.Text)
        Access.AddParam("@Email", Email.Text)
        Access.AddParam("@combobox1", ComboBox1.Text)
        Access.AddParam("@combobox2", ComboBox2.Text)
        Access.AddParam("@combobox3", ComboBox3.Text)
        Access.AddParam("@combobox4", ComboBox4.Text)
        Access.AddParam("@combobox5", ComboBox5.Text)
        Access.AddParam("@combobox6", ComboBox6.Text)
        Access.AddParam("@combobox1", ComboBox1.Text)
        Access.AddParam("@combobox2", ComboBox2.Text)
        Access.AddParam("@combobox3", ComboBox3.Text)
        Access.AddParam("@combobox4", ComboBox4.Text)
        Access.AddParam("@combobox5", ComboBox5.Text)
        Access.AddParam("@combobox6", ComboBox6.Text)
        Access.AddParam("@combobox7", ComboBox7.Text)
        Access.AddParam("@combobox8", ComboBox8.Text)
        Access.AddParam("@combobox9", ComboBox9.Text)
        Access.AddParam("@combobox10", ComboBox10.Text)
        Access.AddParam("@combobox11", ComboBox11.Text)
        Access.AddParam("@combobox12", ComboBox12.Text)
        Access.AddParam("@combobox13", ComboBox13.Text)
        Access.AddParam("@combobox14", ComboBox14.Text)
        Access.AddParam("@combobox15", ComboBox15.Text)
        Access.AddParam("@combobox16", ComboBox16.Text)
        Access.AddParam("@combobox17", ComboBox17.Text)
        Access.AddParam("@combobox18", ComboBox18.Text)
        Access.AddParam("@combobox19", ComboBox19.Text)
        Access.AddParam("@combobox20", ComboBox20.Text)
        Access.AddParam("@combobox21", ComboBox21.Text)
        Access.AddParam("@combobox22", ComboBox22.Text)
        Access.AddParam("@combobox23", ComboBox23.Text)
        Access.AddParam("@combobox24", ComboBox24.Text)
        Access.AddParam("@combobox25", ComboBox25.Text)
        Access.AddParam("@combobox26", ComboBox26.Text)
        Access.AddParam("@combobox27", ComboBox27.Text)
        Access.AddParam("@combobox28", ComboBox28.Text)
        Access.AddParam("@combobox29", ComboBox29.Text)
        Access.AddParam("@combobox30", ComboBox30.Text)
        Access.AddParam("@combobox31", ComboBox31.Text)
  
        Access.AddParam("@CheckBox1", CheckBox1.Checked)
        Access.AddParam("@CheckBox2", CheckBox2.Checked)
        Access.AddParam("@CheckBox3", CheckBox3.Checked)
        Access.AddParam("@CheckBox4", CheckBox4.Checked)
        Access.AddParam("@CheckBox5", CheckBox5.Checked)
      
  

        ' EXECUTE INSERT COMMAND
        Access.ExecQuery("INSERT INTO STOCKAGE (NOM,PRENOM,email,C1,C2,C3,C4,C5,C6,C7,C8,C9,C10,C11,C12,C13,C14,C15,C16,C17,C18,C19,C20,C21,C22,C23,C24,C25,C26,C27,C28,C29,C30,C31,B1,B2,B3,B4,B5) " & _
                         "VALUES (@NOM,@PRENOM,@Email,@combobox1,@combobox2,@combobox3,@combobox4,@combobox5,@combobox6,@combobox7,@combobox8,@combobox9,@combobox10,@combobox11,@combobox12,@combobox13,@combobox14,@combobox15,@combobox16,@combobox17,@combobox18,@combobox19,@combobox20,@combobox21,@combobox22,@combobox23,@combobox24,@combobox25,@combobox26,@combobox27,@combobox28,@combobox29,@combobox30,@combobox31,@combobox32,@CheckBox1,@CheckBox2,@CheckBox3,@CheckBox4,@CheckBox5); ")

        ' REPORT & ABORT ON ERRORS
        If Not String.IsNullOrEmpty(Access.Exception) Then MsgBox(Access.Exception) : Exit Sub

        ' SUCCESS!!
        MsgBox("User was added successfully.")

        Form1.RefreshGrid()

  
    End Sub


EDIT : Correction des balises de code
A voir également:

2 réponses

vb95 Messages postés 3472 Date d'inscription samedi 11 janvier 2014 Statut Contributeur Dernière intervention 13 avril 2024 169
Modifié le 17 nov. 2018 à 23:38
Bonjour !
Je ne pense pas apporter la solution mais dans ton code il y a quelque chose qui me "chiffonne"
Access.AddParam("@combobox31", ComboBox31.Text)
Access.AddParam("@CheckBox1", CheckBox1.Checked)


On n'a pas le code de Access.AddParam et je n'ai trouvé nulle part mention de cette fonction dans l'aide Access ! donc j'en déduis ce qui suit :
La première ligne prend comme paramètre le nom d'un contrôle ( une ComboBox ) puis une chaine de caractères String ( le contenu de la propriété Text de la ComboBox )
La seconde ligne prend comme paramètre le nom d'un contrôle ( une ChekBox) puis son état ( True ou False)
Or l'état d'une CheckBox n'est pas une chaine de caractères mais une variable Booléenne ( qui prend les valeurs True ou False uniquement) . C'est sans doute pour cela que rien ne "s'affiche" pour les champs "Checkbox" de ta base de données

Quelque chose ainsi devrait te donner une piste
if CheckBox1.Checked = True then
       ' le champ B1 de ta base de données est mis à Checked = True
End if

A faire pour les 5 Checkbox sous toute réserve

0
julia Namor Messages postés 524 Date d'inscription jeudi 27 mars 2014 Statut Membre Dernière intervention 13 janvier 2024
18 nov. 2018 à 19:22
Bonjour vb95
Merci de ta réponse, j'avais fini par désespérer.
du coup peux tu me donner une idée de code .
Ma base de données 's'intitule STOKAGE.

' le champ B1 de ta base de données est mis à Checked = True

Merci encore
0
vb95 Messages postés 3472 Date d'inscription samedi 11 janvier 2014 Statut Contributeur Dernière intervention 13 avril 2024 169
Modifié le 18 nov. 2018 à 19:41
Bonjour !
Tout d'abord les champs B1, B2, B3 , B4 et B5 doivent être mis à False à l'initialisation de ta base de données ( non coché) ! Ces champs doivent être du type Boolean ( True ou False )

Ensuite comme dit dans mon premier message , les champs B1 à B5 doivent refléter l'état des 5 ChekbBox

A essayer sous toute réserve
B1 = CheckBox1.Checked 
B2 = CheckBox2.Checked 
B3 = CheckBox3.Checked 
B4 = CheckBox4.Checked 
B5 = CheckBox5.Checked 
0
Rejoignez-nous