Results 1 to 3 of 3

Thread: strsql = "Delete..."

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2006
    Posts
    21

    strsql = "Delete..."

    Hi,

    My code is not deleting the selected record as I wanted to. I think there is something wrong with the line of code, DoCmd.RunSQL ("DELETE FROM UserRole WHERE WindowsUser = " & strDeleteUser)

    Any advice will be greatly appreciated!


    Private Sub cmdDeleteUser_Click()
    Dim Check As Integer
    Dim strDeleteUser As String

    strDeleteUser = Me.txtFillWindowsUser.Value

    Check = MsgBox("Are you sure that you want to delete this user?", vbYesNoCancel)
    If Check = vbCancel Then
    Cancel = True
    ElseIf Check = vbYes Then
    DoCmd.RunSQL ("DELETE FROM UserRole WHERE WindowsUser = " & strDeleteUser)
    DoCmd.Requery
    DoCmd.OpenForm "frmAdmin"
    ElseIf Check = vbNo Then
    No = True
    End If

    End Sub

  2. #2
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    Re: strsql = "Delete..."

    DoCmd.RunSQL ("DELETE FROM UserRole WHERE WindowsUser = '" & strDeleteUser & "'")

    Note the single quote after the equal sign, and the double, single, double quote after strDeleteUser. I also tend to use DELETE * in Access, not sure it's mandatory, though. Some dbs don't allow it.
    Tengo mas preguntas que contestas

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Sep 2006
    Posts
    21

    Re: strsql = "Delete..."

    Thank you soo much!! It worked

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width