OVH Cloud OVH Cloud

VBA : if - if not

2 réponses
Avatar
belok
Bonjour,

J'ai déclarer la variable

Public login As String * 15
Public pass As String * 15

//ça fonctionne avec le msg box donc elle est bien déclarer merciii à
Raymond

__________________________

Maintenant, j'ai attribué la variable à ce qui ce trouve dans cmdlogin &
cmdpassword

Private Sub cmdpassword_LostFocus()
login = cmdlogin
pass = cmdpassword
End Sub

//ça fonctionne avec le msgbox

__________________________

Le problème ce trouve ici, je voudrais qu'il vérifie le contenu des variable
(login,pass) avec les champs d'une table.

en gros ce que je voudrai c'est :

si (variable = champs)
action
sinon
action

//et si le sinon est imposible

si (variable=champs)
action

si pas (variable=champs)
action

comment le traduire en vba ?

Voilà ce que j'ai fait mais ça ne fonctionne pas ?



Private Sub bconnexion_Click()

If (login = [alogin]) Then
MsgBox "la variable correspond a un login", vbOKOnly
End If

If (Not login = [alogin]) Then
MsgBox "la variable ne correspond a un login", vbOKOnly
End If

If (pass = [apassword]) Then
MsgBox "la variable correspond au password", vbOKOnly
End If

If (Not pass = apassword) Then
MsgBox "la variable ne correspond au password", vbOKOnly

End If

End Sub




merci de votre aide,

2 réponses

Avatar
Raymond
Tu peux faire:

If (login = alogin) And (pass = apassword) Then
MsgBox "tout correspond"
Else
MsgBox "recommencer"
End If

Login, à mon avis, est un mot qui peut se retrouver réservé access un jour,
à éviter.
--
@+
Raymond Access MVP.
http://access.seneque.free.fr/
http://access2003.free.fr/
http://users.skynet.be/mpfa/charte.htm pour une meilleure
efficacité de tes interventions sur MPFA.


"belok" a écrit dans le message de
news:3f9befc9$0$3662$

Bonjour,

J'ai déclarer la variable

Public login As String * 15
Public pass As String * 15

//ça fonctionne avec le msg box donc elle est bien déclarer merciii à
Raymond

__________________________

Maintenant, j'ai attribué la variable à ce qui ce trouve dans cmdlogin &
cmdpassword

Private Sub cmdpassword_LostFocus()
login = cmdlogin
pass = cmdpassword
End Sub

//ça fonctionne avec le msgbox

__________________________

Le problème ce trouve ici, je voudrais qu'il vérifie le contenu des
variable

(login,pass) avec les champs d'une table.

en gros ce que je voudrai c'est :

si (variable = champs)
action
sinon
action

//et si le sinon est imposible

si (variable=champs)
action

si pas (variable=champs)
action

comment le traduire en vba ?

Voilà ce que j'ai fait mais ça ne fonctionne pas ?



Private Sub bconnexion_Click()

If (login = [alogin]) Then
MsgBox "la variable correspond a un login", vbOKOnly
End If

If (Not login = [alogin]) Then
MsgBox "la variable ne correspond a un login", vbOKOnly
End If

If (pass = [apassword]) Then
MsgBox "la variable correspond au password", vbOKOnly
End If

If (Not pass = apassword) Then
MsgBox "la variable ne correspond au password", vbOKOnly

End If

End Sub




merci de votre aide,




Avatar
Pierre CFI
bonjour
utilise la fonction Dlookup("nomchamp_id","nomtable","nomchamp_id='" & tavariable & "')
attention il y a des ' avant et aprés le "
pour l'id, pareil pour le mot de passe
cette fonction te retourne ou Null ou la valeur cherchée

donc
If Not isnull(dlookup........ then
good
else
pas good
end if

--
Pierre CFI
MVP Microsoft Access
Mail : http://cerbermail.com/?z0SN8cN53B

Site pour bien commencer
http://users.skynet.be/mpfa/
Site perso
http://access.cfi.free.fr
"belok" a écrit dans le message de news: 3f9befc9$0$3662$

Bonjour,

J'ai déclarer la variable

Public login As String * 15
Public pass As String * 15

//ça fonctionne avec le msg box donc elle est bien déclarer merciii à
Raymond

__________________________

Maintenant, j'ai attribué la variable à ce qui ce trouve dans cmdlogin &
cmdpassword

Private Sub cmdpassword_LostFocus()
login = cmdlogin
pass = cmdpassword
End Sub

//ça fonctionne avec le msgbox

__________________________

Le problème ce trouve ici, je voudrais qu'il vérifie le contenu des variable
(login,pass) avec les champs d'une table.

en gros ce que je voudrai c'est :

si (variable = champs)
action
sinon
action

//et si le sinon est imposible

si (variable=champs)
action

si pas (variable=champs)
action

comment le traduire en vba ?

Voilà ce que j'ai fait mais ça ne fonctionne pas ?



Private Sub bconnexion_Click()

If (login = [alogin]) Then
MsgBox "la variable correspond a un login", vbOKOnly
End If

If (Not login = [alogin]) Then
MsgBox "la variable ne correspond a un login", vbOKOnly
End If

If (pass = [apassword]) Then
MsgBox "la variable correspond au password", vbOKOnly
End If

If (Not pass = apassword) Then
MsgBox "la variable ne correspond au password", vbOKOnly

End If

End Sub




merci de votre aide,