Command Button is not functioning (1 Viewer)

KittyCat

New member
Local time
Today, 12:34
Joined
Nov 25, 2016
Messages
6
Hello there,

I have an issue here where I cannot run my command button in VB Access. There is no error stated but the button just wont function.

Here is the code:


Private Sub Command14_Click()

Dim strOldPassword As String
Dim strSQL As String

strOldPassword = DLookup("[password]", "tblUser", "[LoginID] = '" & Me.List25 & "'")
Select Case strOldPassword
Case Is = Me.Text10
strSQL = "UPDATE tblUser SET Password=" & "'" & Me.Text10 & "' WHERE [LoginID] = " & " & Me.List25 & "
MsgBox "Password has been changed", vbInformation, "Password Changed"
Case Is <> Me.Text6
MsgBox "The Old Password does not match", vbInformation, "Type Correct Old Password"
End Select

End Sub

I also edit setting on Trust Center. But it won't run:confused:

Hope to get your assistance on this! Thank you.
 

moke123

AWF VIP
Local time
Today, 15:34
Joined
Jan 11, 2013
Messages
3,912
This line doesnt look right although it may work
Code:
strSQL = "UPDATE tblUser SET Password=" & "'" & Me.Text10 & "' WHERE [LoginID] = " & " & Me.List25 & "
try
Code:
strSQL = "UPDATE tblUser SET Password= """ &  Me.Text10  & """ WHERE  [LoginID] = """ &  Me.List25  & """"
currentdb.Execute strSQL, dbFailOnError

the reason your code doesnt work is you never execute the sql.
 

KittyCat

New member
Local time
Today, 12:34
Joined
Nov 25, 2016
Messages
6
Still not functioning:(
Is it because of my query or my table? Because i use Email as my id.
hmm
 

JHB

Have been here a while
Local time
Today, 21:34
Joined
Jun 17, 2012
Messages
7,732
..
Is it because of my query or my table? Because i use Email as my id.
hmm
Do you mean as LoginID?
If Me.List25 is a text value then try:
Code:
strSQL = "UPDATE tblUser SET Password= '" &  Me.Text10  & "' WHERE  [LoginID] = '" &  Me.List25  & "'"
 

KittyCat

New member
Local time
Today, 12:34
Joined
Nov 25, 2016
Messages
6
Yes, text.
But the button stil not functioning. I put the incorrect old password (with my new password) and the button detects but when I insert correct old password (with new password), the button is not detecting.

Any idea?
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 20:34
Joined
Jul 9, 2003
Messages
16,272
Does the message box part return a message?

Sent from my SM-G925F using Tapatalk
 

Grumm

Registered User.
Local time
Today, 21:34
Joined
Oct 9, 2015
Messages
395
Maybe it is a good habit to name the controls with a meaningfully name.
Code:
Private Sub Command14_Click()

Dim strOldPassword As String
Dim strSQL As String

strOldPassword = DLookup("[password]", "tblUser", "[LoginID] = '" & Me.List25 & "'")
Select Case strOldPassword
Case Is = Me.Text10 [COLOR="Red"]// Is this the old password or the new ?[/COLOR]
strSQL = "UPDATE tblUser SET Password=" & "'" & Me.Text10 & "' WHERE [LoginID] = " & " & Me.List25 & "
MsgBox "Password has been changed", vbInformation, "Password Changed"
Case Is <> Me.Text6 [COLOR="Red"]// What field is this now ? What is the difference between Text10 and Text6 ?[/COLOR]
MsgBox "The Old Password does not match", vbInformation, "Type Correct Old Password"
End Select

End Sub

See text in red... There are 2 different input values, but you use only one to update the old password...
 

moke123

AWF VIP
Local time
Today, 15:34
Joined
Jan 11, 2013
Messages
3,912
Explain in simple terms exactly what you are trying to do.
Are you changing a password? It isn't clear, especially with control names which have no meaning.
 

moke123

AWF VIP
Local time
Today, 15:34
Joined
Jan 11, 2013
Messages
3,912
Heres a simple demo of a change password procedure since it appears that is what your aiming for. It uses StrComp() to compare the various password entries (old,new, and confirm new) and is case sensitive. It also records the date of change in case you wish to automate a renewal date.
 
Last edited:

KittyCat

New member
Local time
Today, 12:34
Joined
Nov 25, 2016
Messages
6
Heres a simple demo of a change password procedure since it appears that is what your aiming for. It uses StrComp() to compare the various password entries (old,new, and confirm new) and is case sensitive. It also records the date of change in case you wish to automate a renewal date.

Runtime error 2471 occurs.
Is it because of LoginID?
Cause LoginID is a text not number

strSql = "update tblUser set txtPassword = """ & Me.TxtNew & """, dteChanged = #" & Date & "# where LoginID = " & Me.cboUser & "'"

and

Me.TxtHint = "For demo purposes " & Me.cboUser.Column(1) & "'s old Password is " & DLookup("txtPassword", "tblUser", "LoginID = " & Me.cboUser & "'")
 

Grumm

Registered User.
Local time
Today, 21:34
Joined
Oct 9, 2015
Messages
395
You know that SQL doesn't use double quotes ?
You need to use single quotes when updating strings.
So you need :
strSql = "update tblUser set txtPassword = '" & Me.TxtNew & "', dteChanged = #" & Date & "# where LoginID = '" & Me.cboUser & "'"

Same in the DLookup. You are missing the first ' in "LoginID = '" & Me.cboUser & "'"
 

moke123

AWF VIP
Local time
Today, 15:34
Joined
Jan 11, 2013
Messages
3,912
You need to use single quotes when updating strings.
while a single quote will probably suffice for the OP's purposes seeing as they are using an email as an id, i generally prefer using double quotes to account for the possibilty of an apostrophe appearing in the string.
 
Last edited:

KittyCat

New member
Local time
Today, 12:34
Joined
Nov 25, 2016
Messages
6
Thanks a lotmoke123 and Grumm!
The problem is now solved!

I'm happy now! :D
 

Grumm

Registered User.
Local time
Today, 21:34
Joined
Oct 9, 2015
Messages
395
I use single quotes for strings. I work all day with Microsoft SQL manager... If you try to use double quotes, the sql gives a nice error. But in Access you can use both.

But the problem of the OP's query was that he missed the first quote in this part :
Code:
where LoginID = " & Me.cboUser & "'"
 
Last edited:

Users who are viewing this thread

Top Bottom