Ali
Ali

Reputation: 613

VB SQL UPDATE command returns error "Runtime error 424: Object required."

Here's the code:

Dim tr As Transactions
Set tr = New Transactions

Dim ID As Integer
Dim name As String, username As String, password As String, activate As String

name = cmbName.Value
ID = tr.GetUserID(name)

If (AccountActivated = True) Then
    username = txtUsername.Value
    password = txtPassword.Value
    MsgBox name & " " & username & " " & password
    activate = "Yes"
Else
    username = ""
    password = ""
    activate = "No"
End If

tr.UpdateAccount name, username, password, activate 'ERROR HERE: Object required

Here;s the function I'm calling:

 Public Function UpdateAccount(ByVal name As String, ByVal username As String, ByVal password As String, ByVal activation As String)
        Call connectDB
        sSQL = "update User set Username = '" & username & "', Password = '" & password & "', AccountActivated = '" & activation & "' where Name = '" & name & "'"
        MsgBox sSQL
        db.Execute sSQL
 End Function

Upvotes: 1

Views: 537

Answers (1)

ariel
ariel

Reputation: 16150

Why here you use "db" and on the other question "CurrentDb" ? Always code using option explicit.

And why is function, change to sub, i don't remember if this could cause a problem.

But most important, dont use text inputed from text boxes to build a sql string, this makes it easy to be a victim of SQL injection, use parameters.

Upvotes: 2

Related Questions