Results 1 to 4 of 4
  1. #1
    kawi6rr is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    39

    VBA Error: Invalid Bracketing of Name

    I'm trying to insert a value and delete a value in a record based off a check box click event using an ADODB connection. The insert works but when it reaches the ELSEIF statement where i want to delete the entry if the user clicks on the checkbox but realizes they dont want that selected. I'm getting the error above in the title.

    Issue code bolded below




    Private Sub Check_AMI_Click()
    Dim conn As ADODB.Connection
    Dim strSQL As String
    Dim insertValue As String
    Set conn = CurrentProject.Connection

    If Me.Check_AMI.Value = -1 Then

    strSQL = "INSERT INTO Events ( Hospitalization_for ) VALUES( 'AMI-STEMI' )"

    conn.Execute strSQL

    conn.Close
    Set conn = Nothing
    Me.Dirty = False

    Me.Check_AMI.DefaultValue = "0"
    Me.Requery


    ElseIf Me.Check_AMI.Value = 0 Then

    'strSQL = "UPDATE Events ( Hospitalization_for = "")"
    strSQL = "UPDATE [Events] SET [Hospitalization_for] = Null WHERE [Me.EventID] = " & Me.EventID & ""
    conn.Execute strSQL

    conn.Close
    Set conn = Nothing
    Me.Dirty = False

    Me.Check_AMI.DefaultValue = "-1"
    Me.Requery
    End If
    End Sub

    Any help is apprecaited, thanks.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    Me is only valid in VBA code, not in SQL. Try

    strSQL = "UPDATE [Events] SET [Hospitalization_for] = Null WHERE [EventID] = " & Me.EventID
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    kawi6rr is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    39
    Thanks that was it, I must have been sleeping when I wrote that part. I'm having bigger issues with this anyway, I can't seem to get it to update properly when telling it which record to update, it just creates a new entry. And now that I've got part to work I noticed more issues.

    New Error: Query input must contain at least one table or query!

    I actually used the primary key from the master table, dont know what I was thinking with the other one.

    strSQL = "INSERT INTO Events ( Hospitalization_for ) VALUES( 'AMI-STEMI' ) WHERE OutcomeID = " & Me.OutcomeID & ""

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    In an append query, you either use a VALUES clause or a SELECT clause. The WHERE clause is only valid with a SELECT clause; it has no meaning with a VALUES clause, because you're explicitly giving it the value to append. Try

    strSQL = "INSERT INTO Events ( Hospitalization_for ) VALUES( 'AMI-STEMI' )
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 13
    Last Post: 12-12-2012, 08:17 PM
  2. Invalid Relational Operator Error
    By KelleyM in forum Queries
    Replies: 5
    Last Post: 11-08-2012, 10:53 AM
  3. Error 94: Invalid Use of Null
    By athomas8251 in forum Forms
    Replies: 3
    Last Post: 11-09-2011, 11:46 AM
  4. Replies: 3
    Last Post: 04-12-2011, 10:22 AM
  5. Invalid Argument Error
    By koper in forum Access
    Replies: 2
    Last Post: 06-14-2010, 11:22 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums