0

インターネットで解決策を探して頭を悩ませてきましたが、役に立たず、うまくいきませんでした。

strSQL = "Update tTbl_LoginPermissions SET LoginName = '" & StrUserName & "', PWD = '" & StrPWD & "', fldPWDDate = '" & Now() & "'" & _
     "WHERE intLoginPermUserID = " & MyMSIDColumn0

エラーが出たら、実際にこの where 句を使用したいと思います。

'WHERE intLoginPermUserID IN (SELECT intCPIIUserID From vw_ADMIN_Frm_LoginBuilder)

コード全体は次のとおりです。

Dim con As ADODB.Connection
    Dim cmd As ADODB.Command
    Dim strSQL As String
    Const cSQLConn = "DRIVER=SQL Server;SERVER=dbswd0027;UID=Mickey01;PWD=Mouse02;DATABASE=Regulatory;"

Dim StrUserName As String, StrPWD As String

'passing variables
StrUserName = FindUserName()
StrPWD = EncryptKey(Me.TxtConPWD)

    'Declaring the SQL expression to be executed by the server
     strSQL = "Update tTbl_LoginPermissions SET LoginName = '" & StrUserName & "', PWD = '" & StrPWD & "', fldPWDDate = '" & Now() & "#" & _
     "WHERE intLoginPermUserID = " & MyMSIDColumn0
     'WHERE intLoginPermUserID = ANY (SELECT intCPIIUserID From vw_ADMIN_Frm_LoginBuilder)

     Debug.Print strSQL
    'connect to SQL Server
    Set con = New ADODB.Connection
    With con
        .ConnectionString = cSQLConn
        .Open
    End With

    'write back
    Set cmd = New ADODB.Command
    With cmd
        .ActiveConnection = con
        .CommandText = strSQL
        .CommandType = adCmdText
        .Execute
        Debug.Print strSQL
    End With

    'close connections
    con.Close
    Set cmd = Nothing
    Set con = Nothing

       MsgBox "You password has been set", vbInformation + vbOKOnly, "New Password"

最新コード生成エラー:

 '/Declaring the SQL expression to be executed by the server
    strSQL = "Update dbo_tTbl_LoginPermissions " _
    & "SET LoginName = '" & StrUserName & "' " _
    & "SET PWD = '" & StrPWD & "' " _
    & "SET fldPWDDate = '" & Now() & "' " _
    & "WHERE intLoginPermUserID = 3;"

私はこのサイトに行って自分の間違いを見つけようとしましたが、まだ理解できません:

4

3 に答える 3

0

これを試して:

strSQL = "Update tTbl_LoginPermissions SET LoginName = '" & replace(StrUserName, "'", "''") & "', PWD = '" & replace(StrPWD, "'", "''") & "', fldPWDDate = '" & Now() & "'" & _
 "WHERE intLoginPermUserID = " & MyMSIDColumn0
于 2013-11-06T22:12:53.353 に答える
0

これは必然的に私の (') 謎を修正し​​たコードでした:

'/passing variables
StrUserName = FindUserName()
StrPWD = EncryptKey(Me.TxtConPWD)
StrUserId = Me.CboUser.Column(0)

 '/Declaring the SQL expression to be executed by the server
   strSQL = "Update tTbl_LoginPermissions SET " _
    & "LoginName = '" & StrUserName & "' , " _
    & "PWD = '" & StrPWD & "' ," _
    & "fldPWDDate = '" & Now() & "' " _
    & "WHERE intLoginPermUserID = '" & StrUserId & "'"
于 2013-12-11T16:24:36.427 に答える