SQL asks for additional parameter

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • daoxx
    New Member
    • Mar 2008
    • 32

    SQL asks for additional parameter

    Hi
    I've had this problem before and it got solved, except it was with numeric values.
    This time it's with text, and I'm doing it as I did with the numbers.. But it isn't working.

    I have this code in a button:
    Code:
    Private Sub cmdDelName_Click()
    Dim sql2 As String
    Dim n As String
    n = InputBox("Which name do you want to remove?", "Remove name")
    sql2 = "DELETE * FROM Names WHERE [Name]=" & n
    DoCmd.SetWarnings False
    DoCmd.RunSQL sql2
    DoCmd.SetWarnings True
    Me.NameSt.Requery
    Me.NameEnd.Requery
    End Sub
    It shows me the inputbox, then asks me for a parameter. If I input John on the inputbox and John when SQL asks me for a parameter, it will delete John.
    The problem here is that I don't want the parameter box to show up asking me for the same thing.

    Thanks for any assistance.
  • MikeTheBike
    Recognized Expert Contributor
    • Jun 2007
    • 640

    #2
    Originally posted by daoxx
    Hi
    I've had this problem before and it got solved, except it was with numeric values.
    This time it's with text, and I'm doing it as I did with the numbers.. But it isn't working.

    I have this code in a button:
    Code:
    Private Sub cmdDelName_Click()
    Dim sql2 As String
    Dim n As String
    n = InputBox("Which name do you want to remove?", "Remove name")
    sql2 = "DELETE * FROM Names WHERE [Name]=" & n
    DoCmd.SetWarnings False
    DoCmd.RunSQL sql2
    DoCmd.SetWarnings True
    Me.NameSt.Requery
    Me.NameEnd.Requery
    End Sub
    It shows me the inputbox, then asks me for a parameter. If I input John on the inputbox and John when SQL asks me for a parameter, it will delete John.
    The problem here is that I don't want the parameter box to show up asking me for the same thing.

    Thanks for any assistance.
    Hi

    As Name is a text field in the table, then perhaps (just perhaps) this may help

    sql2 = "DELETE * FROM Names WHERE [Name]= '" & n & "'"

    ie. for text field values (n in this case) need to be delimited by apostophes, so that VB knows where the string value starts and ends (this is self evident with numbers !).

    HTH


    MTB

    Comment

    • daoxx
      New Member
      • Mar 2008
      • 32

      #3
      Works perfectly, and now that I think of it.. I've made this error several times!
      I've to write it down ;d

      Thanks :D

      Comment

      Working...