cs_djimson
Messages postés53Date d'inscriptionsamedi 14 octobre 2006StatutMembreDernière intervention23 mai 2017
-
27 déc. 2006 à 10:46
cs_djimson
Messages postés53Date d'inscriptionsamedi 14 octobre 2006StatutMembreDernière intervention23 mai 2017
-
28 déc. 2006 à 10:47
Slt à tous je fais un programme et j'ai des erreurs que j'arrive pas à corriger. Je sais pas si je peux poster tous le code avec le formulaire pour qu'on le corrige pour moi. Merci de m'aider.
cs_djimson
Messages postés53Date d'inscriptionsamedi 14 octobre 2006StatutMembreDernière intervention23 mai 2017 27 déc. 2006 à 11:26
Il est entièrement fait en utilisant la source de donnée ADO. Je sais pas si on peut le convertir en utilisant autres source plus fiable. Merci
'***********************************************************************
' Ce petit programme est fait pour gerer les affections des agents *
' vers un site. Mais ca genère quelques erreurs que je ne comprend pas.
' Le problème se situe au niveau de la sauvegarde.
'***********************************************************************
'Déclaration des variables utilisées
Dim ok As Long
Dim rea As Integer
Private Sub cltm_Click()
If cltm.Value = True Then
cltp.Value = False
cmbpren.Enabled = False
cmbrscm.Enabled = True
End If
End Sub
Private Sub cltp_Click()
If cltp.Value = True Then
cltm.Value = False
cmbpren.Enabled = True
cmbrscm.Enabled = False
End If
End Sub
If Adoagaf.Recordset.RecordCount > 0 Then
Adoagaf.Recordset.MoveFirst
Adoagaf.Recordset.Find ("noagt= '" & txtcagt.Text & "'")
If Adoagaf.Recordset.EOF = False Then
If MsgBox(" CET AGENT A ETE DEJA AFFECTE A UN SITE,VOULEZ VOUS LE REAFFECTER", vbYesNo + vbQuestion, "ALERTE") = vbYes Then
Adoagaf.Recordset.Delete
Call affiche_agt
End If
Else
Call affiche_agt
End If
Else
Call affiche_agt
End If
End Sub
'Code d'affichage d'agent sélectionné
Private Sub affiche_agt()
Adolignaff.CommandType = adCmdTable
Adolignaff.RecordSource = "ligne_affectation"
Adolignaff.Refresh
Adolignaff.Recordset.MoveFirst 'ajouter dernièrement
Do While Adolignaff.Recordset![Numero] <> rea
Adolignaff.Recordset.MoveNext
Loop
If Adoagaf.Recordset.RecordCount > 0 Then
Adoagaf.Recordset.MoveFirst
Adoagaf.Recordset.Find ("noagt= '" & txtcagt.Text & "'")
If Adoagaf.Recordset.EOF = False Then
If MsgBox(" CET AGENT A ETE DEJA AFFECTE A UN SITE,VOULEZ VOUS LE REAFFECTER", vbYesNo + vbQuestion, "ALERTE") = vbYes Then
'supprimer le nbre d'agent ds l'affectation concerné
End Sub
'Code lié au champ nom et prenom
Private Sub cmbpren_change()
' cmbrscm.Enabled = False
If cmbpren.Text <> "" Then
Adocltp.Recordset.MoveFirst
Adocltp.Recordset.Find ("nom_pren_cltp = '" & cmbpren.Text & "'")
If Adocltp.Recordset.EOF = False Then
txtcode.Text = Adocltp.Recordset![nocltp]
End If
End If
End Sub
'Code lié au champ raison social
Private Sub cmbrscm_Change()
If cmbrscm.Text <> "" Then
Adocltm.Recordset.MoveFirst
Adocltm.Recordset.Find ("rscm = '" & cmbrscm.Text & "'")
If Adocltm.Recordset.EOF = False Then
txtcode.Text = Adocltm.Recordset![nocltm]
End If
End If
End Sub
Private Sub cmdajout_Click()
Call initialiser
nbaff = txtnbagt.Text
naf = Adoaff.Recordset.RecordCount
If naf > 0 And Val(txtnbagt) <> 0 Then
Adoagaf.Refresh
Adoagaf.Recordset.MoveFirst
na = Adoagaf.Recordset.RecordCount
If na > 0 Then
Adoagaf.Recordset.CancelUpdate
End If
Call bloc
Call desactive
End If
End Sub
'Procédure permettant de bloquer les boutons
Private Sub bloc()
cmdpremier.Enabled = True
cmdprecedent.Enabled = True
cmdsuiv.Enabled = True
cmdernier.Enabled = True
cmdajout.Enabled = True
cmdnouv.Enabled = True
' cmdmodif.Enabled = True
cmdannuler.Enabled = False
cmdquit.Enabled = True
cmdsupp.Enabled = True
cmdsauv.Enabled = False
End Sub
'Procédure pour desactiver les champs de saisie
Private Sub desactive()
txtdateaff.Enabled = False
txtnbagt.Enabled = False
cmbnomagt.Enabled = False
txtct.Enabled = False
grilleaffect.AllowUpdate = False
End Sub
Private Sub cmdcons_Click()
Formlistecontrat.Show
End Sub
Private Sub cmdernier_Click()
If Adoaff.Recordset.RecordCount > 0 Then
Adoaff.Recordset.MoveLast
Call actualiser
End If
End Sub
Private Sub cmdmodif_Click()
cmbaagt.Visible = True
Call initialiser
naf = Adoaff.Recordset.RecordCount
If naf > 0 Then
Adoagaf.Refresh
Adoagaf.Recordset.MoveFirst
If Adoagaf.Recordset.EOF = False Then
Adoagaf.Recordset.MoveNext
End If
Loop
End If
rep = InputBox("NUMERO DE L'AGENT A REMPLACER:", "NUMERO")
rea = Val(rep)
'Adolignaff.Refresh
Call debloc
grilleaffect.AllowUpdate = True
cmbnomagt.Enabled = False
End Sub
'Code du bouton NOUVELLE(S)
Private Sub cmdnouv_Click()
Call debloc
Call active
Call initialiser
nbenr = Adoaff.Recordset.RecordCount
If nbenr > 0 Then
Adoaff.Recordset.MoveLast
If nbenr < 10 Then
ok = Right(Adoaff.Recordset![noaff], 1)
Else
If nbenr >= 10 And nbenr < 100 Then
ok = Right(Adoaff.Recordset![noaff], 2)
Else
If nbenr >= 100 And nbenr < 1000 Then
ok = Right(Adoaff.Recordset![noaff], 2)
Else
If nbenr >= 1000 And nbenr < 10000 Then
ok = Right(Adoaff.Recordset![noaff], 4)
Else
If nbenr >= 10000 Then
ok = Right(Adoaff.Recordset![noaff], 5)
End If
End If
End If
End If
End If
End If
Adoaff.Recordset.AddNew
txtdateaff.Text = Date
txtnbagt.Text = InputBox("Nombre d'agents à affecter :", "NOMBRE D'AGENTS")
End Sub
'Code permettant d'initialiser la grille
Private Sub initialiser()
Adolignaff.CommandType = adCmdTable
Adolignaff.RecordSource = "ligne_affectation"
Adolignaff.Refresh
nla = Adolignaff.Recordset.RecordCount
If nla > 0 Then
Adolignaff.Recordset.MoveFirst
Do While nla > 0 And Adolignaff.Recordset.EOF = False
Adolignaff.Recordset.Delete
Adolignaff.Recordset.MoveNext
nla = Adolignaff.Recordset.RecordCount
Loop
End If
End Sub
Private Sub cmdprecedent_Click()
If Adoaff.Recordset.RecordCount > 0 And Adoaff.Recordset.BOF = False Then
Adoaff.Recordset.MovePrevious
Call actualiser
Else
If Adoaff.Recordset.RecordCount > 0 And Adoaff.Recordset.BOF = True Then
MsgBox "Ceci est la première affectation effectuéé", vbOKOnly + vbExclamation, "ALERTE"
Adoaff.Recordset.MoveNext
Call actualiser
End If
End If
End Sub
Private Sub cmdpremier_Click()
If Adoaff.Recordset.RecordCount > 0 Then
Adoaff.Recordset.MoveFirst
Call actualiser
End If
End Sub
Private Sub cmdquit_Click()
Unload Me
End Sub
Private Sub cmdret_Click()
rep = InputBox("NUMERO DE L'AGENT A RETIRER:", "NUMERO")
Adoagaf.Refresh
Adoagaf.Recordset.MoveFirst
'chercher le numero de l'affectation dans agent_affectation
Adoagaf.Recordset.Find ("noaff= '" & txtnum.Text & "'")
Do While Adoagaf.Recordset.EOF = False
If Adoagaf.Recordset.EOF = False Then
Adoagaf.Recordset.MoveNext
End If
Else
If Adoagaf.Recordset.EOF = False Then
Adoagaf.Recordset.MoveNext
End If
End If
Loop
Call actualiser
End Sub
'Code associé au bouton SAUVER
Private Sub cmdsauv_Click()
Call sauvegarde
Call actualiser
Call bloc
Call desactive
cmbaagt.Visible = False
End Sub
'Procédure permettant la sauvegarde des données de la grille
'************************************************************
'Le vrai problème se situe là!!!!!!!!!!!!!!!!!
Private Sub sauvegarde()
Dim noag
Dim cagt
Dim duree As Integer
Adolignaff.Recordset.MoveFirst
af = txtnum.Text
cli = txtcode.Text
Do While Adolignaff.Recordset.EOF = False
If Adolignaff.Recordset![noagt] <> "" Then
num = Adolignaff.Recordset![Numero]
cagt = Adolignaff.Recordset![noagt]
duree = Adolignaff.Recordset![duree_aff_agt]
'Enregistrement dans la table agent_affectation
nag = Adoagaf.Recordset.RecordCount
If nag > 0 Then
Adoagaf.Recordset.MoveFirst
Do While Adoagaf.Recordset.EOF = False
'chercher le numero de l'affectation dans agent_affectation
Adoagaf.Recordset.Find ("noaff= '" & af & "'")
noag = Adoagt.Recordset![noagt]
If Adoagaf.Recordset![Numero] = num Then 's'il existe
'trouver l 'agent qui n'en fait plus parti et le mettre à jour
Private Sub cmdsuiv_Click()
If Adoaff.Recordset.RecordCount > 0 And Adoaff.Recordset.EOF = False Then
Adoaff.Recordset.MoveNext
Call actualiser
Else
If Adoaff.Recordset.RecordCount > 0 And Adoaff.Recordset.EOF = True Then
MsgBox "Ceci est la dernière affectation effectuéé", vbOKOnly + vbExclamation, "ALERTE"
Adoaff.Recordset.MovePrevious
Call actualiser
End If
End If
End Sub
Private Sub cmdsupp_Click()
If MsgBox("SUPPRESSION DE L'AFFECTATION EFFECTUEE POUR LE CLIENT" & cmbpren.Text, vbYesNo + vbQuestion, "SUPPRIMER") = vbYes Then
Adoagt.Recordset.MoveFirst
Do While Adoagt.Recordset.EOF = False
If Adoagt.Recordset![noaff] = txtnum.Text Then
Adoagt.Recordset![noaff] = ""
Adoagt.Recordset![noclient] = ""
Adoagt.Recordset.Update
Adoagt.Recordset.MoveNext
Else
Adoagt.Recordset.MoveNext
End If
Adoagaf.Recordset.MoveFirst
Do While Adoagaf.Recordset.EOF = False
If Adoagaf.Recordset![noaff] = txtnum.Text Then
Adoagaf.Recordset.Delete
Adoagaf.Recordset.MoveNext
Adoagaf.Recordset.MoveNext
End If
Adoagaf.Recordset.MoveNext
Loop
Adolignaff.CommandType = adCmdTable
Adolignaff.RecordSource = "ligne_affectation"
Adolignaff.Refresh
Adolignaff.Recordset.MoveFirst
Do While Adolignaff.Recordset.EOF = False
Adolignaff.Recordset.Delete
Adolignaff.Recordset.MoveNext
Loop
Adoaff.Recordset.Delete
Adoaff.Recordset.MoveFirst
End If
End Sub
Private Sub form_load()
Call actualiser
grilleaffect.AllowUpdate = False
End Sub
'Code pour éviter les doublons dans affectation
Private Sub verif()
nb = Adoaff.Recordset.RecordCount + 1
Adoaff.Recordset.MoveLast
If Adoaff.Recordset![noaff] = txtnum.Text Then
Call cle_cree
End If
End Sub
'Code recherchant le client concerné par une affectation
Private Sub affich()
num = txtnum.Text
If Adoagt.Recordset.RecordCount > 0 Then
Adoagt.Recordset.MoveFirst
Adoagt.Recordset.Find ("noaff= '" & num & "'")
If Adoagt.Recordset.EOF = False Then
client = Adoagt.Recordset![noclient]
End If
End If
If Adocltp.Recordset.RecordCount > 0 Then
Adocltp.Recordset.MoveFirst
Adocltp.Recordset.Find ("nocltp= '" & client & "'")
If Adocltp.Recordset.EOF = False Then
cmbpren = Adocltp.Recordset![nom_pren_cltp]
txtcode = Adocltp.Recordset![nocltp]
cmbrscm.Text = ""
End If
End If
If Adocltm.Recordset.RecordCount > 0 Then
Adocltm.Recordset.MoveFirst
Adocltm.Recordset.Find ("nocltm= '" & client & "'")
If Adocltm.Recordset.EOF = False Then
cmbrscm = Adocltm.Recordset![rscm]
txtcode = Adocltm.Recordset![nocltm]
cmbpren.Text = ""
End If
End If
End Sub
'Code d'actualisation
Private Sub actualiser()
Adolignaff.CommandType = adCmdText
Adolignaff.RecordSource = "select numero,agents.noagt,nom_pren_agt,duree_aff From agent_aff INNER JOIN agents ON agent_aff.noagt=agents.noagt WHERE agent_aff.noaff= '" & txtnum.Text & "'"
grilleaffect.AllowUpdate = False
Call affich
End Sub
Private Sub grilleaffect_AfterColEdit(ByVal ColIndex As Integer)
Select Case ColIndex
Case 3 'Contrôle de la durée de l'affectation
If grilleaffect.Columns(3).Value > 12 Then
MsgBox "LA DUREE NE DOIT PAS EXEDER 12 MOIS "
Else
If grilleaffect.Columns(3).Value <= 0 Then
MsgBox "LA DUREE NE DOIT PAS ETRE INFERIEURE A ZERO "
Else
Adolignaff.Recordset.Update
Adolignaff.Recordset.MoveNext
End If
End If
End Select
End Sub
Private Sub txtct_lostfocus()
Adoctr.Refresh
ct = Trim(txtct.Text)
Adoctr.Recordset.MoveFirst
Adoctr.Recordset.Find ("noctr='" & ct & "'")
If Adoctr.Recordset.EOF = False Then
txtdatectr.Text = Adoctr.Recordset![datecontrat]
Else
MsgBox "NUMERO DE CONTRAT MAL ORTHAGRAPHIE", vbOKOnly, "ATTENTION"
End If
End Sub
Vous n’avez pas trouvé la réponse que vous recherchez ?
cs_djimson
Messages postés53Date d'inscriptionsamedi 14 octobre 2006StatutMembreDernière intervention23 mai 2017 27 déc. 2006 à 12:45
A l'execution tout marche sauf que quuand je clique sur sauver on me dit que BOF ou EOF est egale à TRUE ou que l'enregistrement actuel a été supprimer et que l'opération demandée necessite un nouvel enregistrement. Dc l'affectation ne marche pas.