EXEMPLE

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
Dim demande As Integer
demande = Input("quelle valeur ?")
If demande = Dlookup("tonchamp","tatable","critere") Then
Msgbox "Valeur deja presente"
Else
MsgBox "pas encore presente"
End If


J'ai intégré l'exemple dans mon code, mais j'ai toujours après le test de comparaison le renvoi vers l'erreur" Command1_Error:"
Je ne vois pas où est l'incohérence !

Pouvez vous m'orienter vers une solution ?
Merci
Cordialement
Ci joint le code (partie en italique posant l'erreur)


Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
'CREAT_LISTE_PAYS_Click
Public Sub CREAT_LISTE_PAYS_Click()
Dim rst As DAO.Recordset
', Album As Recordset
'Dim qdReq As QueryDef
Dim NALBUM As String
Dim ANNEE1 As Variant
Dim ANNEE2 As Variant
Dim dbs As DAO.Database
Dim tdf As DAO.TableDef
ANNEE1 = Format(Numeric, "9999")
ANNEE2 = Format(Numeric, "9999")
NALBUM = 0
Set dbs = CurrentDb
On Error GoTo Command1_Error

'ChDrive "R:"
'ChDir ("R:\")
NomPAYS = Forms![Pays Menu]![Liste Pays]
If IsNull(NomPAYS) Then
MsgBox "Veuillez choisir un Pays !"
GoTo FIN
ElseIf Dir("R:\" + NomPAYS, vbDirectory) = NomPAYS Then
MsgBox "La collection " + NomPAYS + " existe !"
GoTo Album
ElseIf Dir("R:\" + NomPAYS, vbDirectory) <> NomPAYS Then
MsgBox "La collection " + NomPAYS + " n'existe pas !"
Pays:
ChDrive "R:"
ChDir ("R:\")
NomPAYS = Forms![Pays Menu]![Liste Pays]
MkDir$ (NomPAYS)
ChDir (NomPAYS)
MsgBox "Le répertoire " + NomPAYS + " est bien créé"
MsgBox "La Liste Albums va être créée !"
Set dbs = CreateDatabase("Liste Albums", dbLangGeneral)
Set tdf = dbs.CreateTableDef("Album")
'Set Index = tdf.CreateIndex("N°Album")
'Index.Primary = True

With tdf
tdf.Fields.Append tdf.CreateField("PAYS", dbText)
tdf.Fields.Append tdf.CreateField("N°Album", dbInteger)
tdf.Fields.Append tdf.CreateField("ANNEE DEBUT", dbInteger)
tdf.Fields.Append tdf.CreateField("ANNEE FIN", dbInteger)
End With
Album:
ChDrive "R:"
ChDir ("R:\")
ChDir (NomPAYS)
'NomPAYS = Forms![Pays Menu]![Liste Pays]
Set dbs = OpenDatabase("Liste Albums")
Set rst = dbs.OpenRecordset("Album")
Set dbs = CurrentDb


NomPAYS = Forms![Pays Menu]![Liste Pays]
NALBUM = InputBox("N° de l'Album: ")
If NALBUM = DLookup("N°Album", "Album", "NomPAYS") Then
 MsgBox "enregistrement " + NALBUM + " trouvé"
Else
MsgBox ("enregistrement " + NALBUM + " non trouvé!")

ANNEE1 = InputBox("ANNEE DEBUT : ")
ANNEE2 = InputBox("ANNEE FIN : ")
rst.AddNew
 rst("Pays") = NomPAYS
 rst("N°Album") = NALBUM
 rst("ANNEE DEBUT") = ANNEE1
 rst("ANNEE FIN") = ANNEE2
 rst.Update
 rst.Close
MsgBox "La Collection " + NomPAYS + " existe, N° de l'Album : " + NALBUM + " Années : " + ANNEE1 + " / " + ANNEE2 + " ."
'Else
'GoTo Pays
'dbs.Close
GoTo FIN

Command1_Error:
If Err.Number = 76 Or 68 Then
MsgBox "Veuiller connecter le disque R: et choisir un Pays!"
GoTo FIN
Else
'Exit Sub
GoTo Pays

End If
End If
End If
FIN:
dbs.Close
End Sub