Description

gestion des cd, code debutant , vb/access

Source / Exemple :


Dim opt As String

Option Explicit
Option Compare Text ' binary '
Public bd As Database
Public util As Recordset
Sub textshow(o As Boolean)
matricul.Enabled = o
nom.Enabled = o
contenu.Enabled = o
autre.Enabled = o
oui.Enabled = o
non.Enabled = o
typelist.Enabled = o
cdlist.Enabled = o
End Sub
Sub boutonshow(o As Boolean)
ajout.Enabled = o
modif.Enabled = o
suppr.Enabled = o
cherch.Enabled = o

valider.Enabled = Not o
annuler.Enabled = Not o

prem.Enabled = o
prec.Enabled = o
suiv.Enabled = o
dern.Enabled = o

End Sub

Sub afficher()
Dim i As Integer
With util
matricul = !matricul
nom = !nom
contenu = !contenu
autre = !autre
oui.Value = False
non.Value = False

If !Type <> "" Then
For i = 0 To 6
If !Type = typelist.List(i) Then
  typelist.ListIndex = i
End If
Next i
End If

If !cd <> "" Then
For i = 0 To 1
If !cd = cdlist.List(i) Then
  cdlist.ListIndex = i
End If
Next i
End If

Select Case !disponible
  Case "oui"
     oui.Value = True
  Case "non"
     non.Value = True
End Select
End With
End Sub

Private Sub ajout_Click()
matricul = ""
nom = ""
contenu = ""
autre = ""
oui.Value = False
non.Value = False
typelist.ListIndex = -1
cdlist.ListIndex = 0
util.AddNew
Call textshow(True)
Call boutonshow(False)
End Sub

Private Sub annuler_Click()
Call textshow(False)
Call boutonshow(True)
Call prec_Click
Call suiv_Click
End Sub

Private Sub cherch_Click()
Dim nom As String
Dim ret As VbCallType
If util.RecordCount <> 0 Then
 ret = MsgBox("OUI pour une rechercher par *Nom* //NON pour une recherche par *Matricule* : ", vbYesNoCancel + vbQuestion)
 If ret = vbYes Then
   nom = InputBox("Entrer le nom du CD/DVD : ", "Recherche : Par Nom")
   nom = "[nom]='" & nom & "'"
 End If
 If ret = vbNo Then
   nom = InputBox("Entrer le Numero du Matricule : ", "Recherche : Par Matricul ")
   nom = "[matricul]='" & nom & "'"
 End If
 If ret <> vbCancel Then
   util.FindFirst (nom)
   If Not util.NoMatch Then
     Call afficher
   Else
   MsgBox "     aucun resultat trouver    ", vbOKOnly + vbInformation
   End If
 End If
Else
  MsgBox " aucune information n'est enregistrer ! ", vbOKOnly + vbCritical
End If
End Sub

Private Sub dern_Click()
If util.RecordCount <> 0 Then
  util.MoveLast
  Call afficher
  End If
End Sub
Sub ouvrir()
Set bd = OpenDatabase("cd1.mdb")
Set util = bd.OpenRecordset("mescd", dbOpenDynaset)
End Sub

Private Sub Form_Load()
Call ouvrir
Call prem_Click
typelist.AddItem "film"
typelist.AddItem "program"
typelist.AddItem "jeu"
typelist.AddItem "music"
typelist.AddItem "etude"
typelist.AddItem "islam"
typelist.AddItem "autre"
cdlist.AddItem "CD"
cdlist.AddItem "DVD"

If util.RecordCount <> 0 Then
Call afficher
Else
MsgBox " aucune information n'est enregistrer ! ", vbOKOnly + vbCritical
End If
Call textshow(False)
Call boutonshow(True)
End Sub

Private Sub modif_Click()
If util.RecordCount <> 0 Then
util.Edit
Call textshow(True)
Call boutonshow(False)
Else
MsgBox " aucune information n'est enregistrer ! ", vbOKOnly + vbCritical
End If

End Sub

Private Sub prec_Click()
 If util.RecordCount <> 0 Then
util.MovePrevious
If util.BOF Then
 util.MoveLast
End If
Call afficher
End If
End Sub

Private Sub prem_Click()
If util.RecordCount <> 0 Then
  util.MoveFirst
  Call afficher
  End If
End Sub

Private Sub quitter_Click()
End
End Sub

Private Sub suiv_Click()
  If util.RecordCount <> 0 Then
util.MoveNext
If util.EOF Then
 util.MoveFirst
 End If
Call afficher
End If
End Sub

Private Sub suppr_Click()
Dim ret As VbCallType
If util.RecordCount <> 0 Then
ret = MsgBox("Etes vous sure de vouloire supprimer " + nom + " ?", vbCritical + vbYesNo, "Confirmer")
If ret = vbYes Then
util.Delete
Call prec_Click
If util.RecordCount <> 0 Then
Call afficher
End If
End If
Else
MsgBox " Aucune information n'est enregistré ! ", vbOKOnly + vbCritical
End If

End Sub

Private Sub valider_Click()
   Call textshow(False)
   Call boutonshow(True)
   With util
    !nom = nom
    !matricul = matricul
    !contenu = contenu
    !autre = autre
    !Type = typelist.List(typelist.ListIndex)
    !cd = cdlist.List(cdlist.ListIndex)
    If oui.Value = True Then
      !disponible = "oui"
    Else
     If non.Value = True Then
       !disponible = "non"
     End If
    End If
   End With
   util.Update
   
End Sub

Conclusion :


code debutant pour apprendre a gerer une base de donnee access sur vb
yms

Codes Sources

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.