Value (1 Viewer)

TajikBoy

New member
Local time
Today, 05:53
Joined
Mar 4, 2011
Messages
21
Hi guys,

I have this code for password change on a form, but cannot get it to work, keeps asking value for intUserID on execution, where as I already have assigned in green highlight , cboEmployee is a unbound filed on the form

WHere am I going wrong?
Code:
Private Sub Command147_Click()
Dim intUserID As Integer
Dim strOldPassword As String
'Check to see if data is entered into the password box
    If IsNull(Me.TxtCurrent) Or Me.TxtCurrent = "" Then
        MsgBox "You must enter your current password", vbOKOnly, "Required Data"
        Me.TxtCurrent.SetFocus
        Exit Sub
    End If
    If Me.txtNew <> Me.TxtNew2 Then
        MsgBox "You must enter your new password correctly in fields", vbOKOnly, "Required Data"
        Me.txtNew.SetFocus
        Exit Sub
    End If

intUserID = Me.cboEmployee
strOldPassword = DLookup("[strEmpPassword]", "tblEmployees", "[lngEmpID]=" & intUserID)

Code:
Select Case strOldPassword
Case Is = Me.TxtCurrent
    
    UserID = Me.cboEmployee
    Me.txtNew.SetFocus
    Dim strSQL As String
    strSQL = "UPDATE tblEmployees SET strEmpPassword = '" & Me.txtNew.Text & "' WHERE lngEmpID = intUserID"
    DoCmd.RunSQL strSQL
 
Last edited by a moderator:

Gasman

Enthusiastic Amateur
Local time
Today, 13:53
Joined
Sep 21, 2011
Messages
8,752
That is because you have not concatenated intuserid into the SQL string
 

TajikBoy

New member
Local time
Today, 05:53
Joined
Mar 4, 2011
Messages
21
That is because you have not concatenated intuserid into the SQL string
Sorry how do I do that? Im not that great when it comes to SQL
 

Gasman

Enthusiastic Amateur
Local time
Today, 13:53
Joined
Sep 21, 2011
Messages
8,752
LOL... Absolute pure luck my friend......
Code:
strSQL = "UPDATE tblEmployees SET strEmpPassword = '" & Me.txtNew.Text & "' WHERE lngEmpID = " & intUserID
assuming intUserID is numeric

Tip:
Add a Debug.Print strSQL after such code and then you can check it is correct. Then comment out or delete when working.
Do the same for DLookUp() if more than one criteria. I would build the criteria and then use that in the domain function.
 

TajikBoy

New member
Local time
Today, 05:53
Joined
Mar 4, 2011
Messages
21
Code:
strSQL = "UPDATE tblEmployees SET strEmpPassword = '" & Me.txtNew.Text & "' WHERE lngEmpID = " & intUserID
assuming intUserID is numeric

Tip:
Add a Debug.Print strSQL after such code and then you can check it is correct. Then comment out or delete when working.
Do the same for DLookUp() if more than one criteria. I would build the criteria and then use that in the domain function.
Thanks a lot mate, I'm seriously struggling with " and 's when it comes to SQL, will learn one day....
 

Gasman

Enthusiastic Amateur
Local time
Today, 13:53
Joined
Sep 21, 2011
Messages
8,752
If it is text surround with single quotes, unless the string has a single quote like Mc'Neil, then I think 3 double quotes will work? I allways need to experiment. :(
Numerics need no surrounding characters
Dates need #

Again debug.print is your friend. :)
 

theDBguy

I’m here to help
Staff member
Local time
Today, 05:53
Joined
Oct 29, 2018
Messages
16,078
Thanks a lot mate, I'm seriously struggling with " and 's when it comes to SQL, will learn one day....
Hi. See if this article helps clarify some of that.

 

Users who are viewing this thread

Top Bottom