Toon posts:

[Access] Password update module werk niet

Pagina: 1
Acties:

Verwijderd

Topicstarter
Hallo!

Omdat ik geen goede programmeur ben heb ik de volgende code "bijelkaar" gesprokkeld. Het is de bedoeling dat een gebruiker een wachtwoord kan veranderen via een formulier.
Nu geeft het compilen van de code geen foutmelding, maar als ik het ga gebruiken dan krijg ik een foutmelding dat er te weinig parameters gedefinieerd staan. Maar ik snap niet welke? Alles zou goed moeten verwijzen e.d.????

Deze code staat achter knop submit op formulier...

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Private Sub cmdSubmit_Click()
Dim UpdatePW As New MyTestClass3

    If Me.filledCheck = False Then
        MsgBox "Please complete all entries before " & _
            "submitting your new password.", vbInformation, _
            "Warning"
    ElseIf txtPassword <> txtConfirm Then
        MsgBox "Password and Confirm Password do not " & _
            "match.  Re-enter one or both.", vbInformation, _
            "Warning"
    Else
        UpdatePW.NewPW (txtEmpID), (txtPassword)
    End If
        
End Sub


De module MyTestClass3 ziet er als volgt uit:

code:
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
Sub NewPW(txtEmpID As String, txtPassword As String)
Dim cmd1 As Command
Dim strSQL As String

'Assign the command reference and connection.
    Set cmd1 = New ADODB.Command
    cmd1.ActiveConnection = CurrentProject.Connection
    
'Define the SQL string; notice
'the insertion of passed arguments.
    strSQL = "UPDATE gebruikers " & _
        "SET gebruikers.password = """ & txtPassword & """ " & _
        "WHERE user_id=" & txtEmpID & ";"
    Debug.Print strSQL
    
'Assign the SQL string to the command and run it.
    cmd1.CommandText = strSQL
    cmd1.CommandType = adCmdText
    cmd1.Execute
    
'Confirmation message
    MsgBox "Your new password is accepted.  " & _
        "Return to Employee Authentication or " & _
        "Exit this form.", vbInformation, _
        "Confirmation"

End Sub


En ik kan de fout maar niet vinden.
Het veld user_id en password in de tabel gebruikers zijn beide van het type text.

Als iemand mij kan helpen, gaarne...want ik zie het echt niet.

Verwijderd

Haal de haakjes eens weg bij "UpdatePW.NewPW (txtEmpID), (txtPassword)"

Verwijderd

Topicstarter
Verwijderd schreef op 24 oktober 2002 @ 15:36:
Haal de haakjes eens weg bij "UpdatePW.NewPW (txtEmpID), (txtPassword)"
Heb ik gedaan. Maar krijg nu de volgende foutmelding:
code:
1
2
3
Run-time error '-2147217904(8004e10)':

No value give  for one more required parameters.


De code ziet er nu als volgt uit:
code:
1
2
3
Else
        UpdatePW.NewPW txtEmpID, txtPassword
End If


En wat ik ook probeer...krijg het niet voor elkaar :(

Verwijderd

Op welke regel code krijg je de foutmelding ? Access geeft dat aan door een gele balk. Dat is nl wat makkelijker zoeken dan zelf compiler (in m'n hoofd) te spelen :)

Verwijderd

Topicstarter
Compiler spelen is toch de droom van elke jongen man/vrouw ;)

Sorry. Back to work...

De gele balk staat bij de regel die ik in de post hiervoor beschreven heb.

code:
1
2
3
Else
        UpdatePW.NewPW txtEmpID, txtPassword
End If

Verwijderd

Allereerst achter submit knop op form

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Private Sub cmdSubmit_Click()
    If Me.filledCheck = False Then
        MsgBox "Please complete all entries before " & _
            "submitting your new password.", vbInformation, _
            "Warning"
    ElseIf txtPassword <> txtConfirm Then
        MsgBox "Password and Confirm Password do not " & _
            "match.  Re-enter one or both.", vbInformation, _
            "Warning"
    Else
        NewPW (txtEmpID), (txtPassword)
    End If
        
End Sub

Vervolgens in de module onderstaande code
code:
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
Sub NewPW(txtEmpID As String, txtPassword As String)
Dim dbs As Database
Dim strSQL As String

Set dbs = CurrentDb
    
'Define the SQL string; notice
'the insertion of passed arguments.
    strSQL = "UPDATE gebruikers " & _
        "SET password ='" & txtPassword & "'" & _
        "WHERE user_id='" & txtEmpID & "';"
    Debug.Print strSQL
    
dbs.Execute (strSQL)
    
'Confirmation message
    MsgBox "Your new password is accepted.  " & _
        "Return to Employee Authentication or " & _
        "Exit this form.", vbInformation, _
        "Confirmation"

dbs.Close
Set dbs = Nothing

End Sub

Je zult wellicht nog moeten testen of de gebruiker bestaat!

[Edit]
Dit was echt fout
code:
1
"WHERE user_id=" & txtEmpID & ";"

Aangezien beide van het type text zijn ben je hier de extra ' vergeten.
Verder heb ik enkele codestukken vervangen door andere objecten.

Verwijderd

Topicstarter
Sorry dat ik niet enorm snel gereageerd heb, maar had het nogal druk met andere dingen. Afijn ik vanmorgen kijken naar de nieuwe oplossing. Stomweg ctrl-c/v gedaan en krijg de volgende melding:

Sub not defined....de compiler stopt dan bij:

code:
1
Private Sub cmdSubmit_Click()


Any idea???

  • mauriceb
  • Registratie: Maart 2001
  • Laatst online: 24-08 23:23
Kun je gewoon alles terugzetten zoals het was en strSQL aanpassen.
Je zegt namelijk dat zowel veld user_id en password strings zijn, dit houdt dat dus ook de WHERE selectie tussen aanhalingstekens moet zetten.

Zoiets dus:

code:
1
2
3
4
5
6
7
8
9
strSQL = "UPDATE gebruikers " & _
         "SET gebruikers.password = """ & txtPassword & """ " & _
         "WHERE user_id = """ & txtEmpID & "";"

of

strSQL = "UPDATE gebruikers " & _
         "SET gebruikers.password = '" & txtPassword & "' " & _
         "WHERE user_id = '" & txtEmpID & "'"


Als je tijdens het compileren geen fout krijgt dan zit de fout meestal in de SQL code die je gebruikt.

Verwijderd

Topicstarter
Goed. Ik weer van 0 begonnen.
De code is nu als volgt:

Voor de submit button:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Private Sub cmdSubmit_Click()
   Dim UpdatePW As New MyTestClass3
   
    If Me.filledCheck = False Then
        MsgBox "Please complete all entries before " & _
            "submitting your new password.", vbInformation, _
            "Achtung"
    ElseIf txtPassword <> txtConfirm Then
        MsgBox "Password and Confirm Password do not " & _
            "match.  Re-enter one or both.", vbInformation, _
            "Achtung"
    Else
        UpdatePW.NewPW (txtEmpID), (txtPassword)
    End If
        
End Sub


Voor de module:
code:
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
Sub NewPW(txtEmpID As String, txtPassword As String)
Dim cmd1 As Command
Dim strSQL As String

'Assign the command reference and connection.
    Set cmd1 = New ADODB.Command
    cmd1.ActiveConnection = CurrentProject.Connection
    
'Define the SQL string; notice
'the insertion of passed arguments.
    strSQL = "UPDATE gebruikers " & _
         "SET gebruikers.password = '" & txtPassword & "' " & _
         "WHERE user_id = '" & txtEmpID & "'"
    Debug.Print strSQL
    
'Assign the SQL string to the command and run it.
    cmd1.CommandText = strSQL
    cmd1.CommandType = adCmdText
    cmd1.Execute
    
'Confirmation message
    MsgBox "Your new password is accepted.  " & _
        "Return to Employee Authentication or " & _
        "Exit this form.", vbInformation, _
        "Achtung"

End Sub


En hij doet het!!! Dank voor jullie hulp! _/-\o_

/me blij is!
Pagina: 1