Results 1 to 6 of 6
  1. #1
    f15e is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2016
    Posts
    75

    MS Access 2010 Insert Into CheckBox syntax

    I am having trouble finding a good example of adding a new record into a table that has a CheckBox (yes/no). I keep getting errors in my insert into query.




    CurrentDb.Execute "INSERT INTO Weight_Data_Tbl([ITEM NO], [TAG], [DESCRIPTION], [EXISTS])" & _
    "VALUES(" & Me.wtItem_txtbx & ", '" & Me.tag_txtbx & "', '" & Me.descrip_txtbx & "', " & Me.exists_chkbx & ")"

    ITEM NO = integer value, TAG = string value, DESCRIPTION = string value, and EXISTS = yes/no checkbox

    My issue is the red highlighted part. What is the correct syntax for inserting check boxes? Single quotes, double quotes, nothing? Thanks in advance.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    just build a query. no need for code.

    but , you could try, (the space at the VALUE word to not run together the command)
    " VALUES(" & Me.wtItem_txtbx & ", '" & Me.tag_txtbx & "', '" & Me.descrip_txtbx & "', " & me.exists_chkbx.value & ")"
    IF that is the correct name of the box

  3. #3
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Just an FYI....

    [ITEM NO] <--- should not use spaces in object names.

    [TAG], [DESCRIPTION] & [EXISTS] are all reserved words in Access and shouldn't be used as object names. Plus, they are not very descriptive.
    See http://allenbrowne.com/AppIssueBadWord.html


    Do you have a control named "exists_chkbx" on the form?

  4. #4
    f15e is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2016
    Posts
    75
    Yes I see they are reserved words but that's not my problem. I could change them but at this point they work fine without errors. exists_chkbox is a checkbox control on my main form. What I am looking to do is have the user either check, or not, the exists_chkbx checkbox control along with other info and when they click the save button, the checkbox status will be reflected in the tables yes/no field (along with the other info but I'm specifically interested in the checkbox syntax in the Insert Into / Values query that keeps producing errors). I have a corresponding checkbox on my datasheet view subform. So there's a checkbox on the main form for user interface and a checkbox on my subform to capture the response where it will be saved in my table as yes/no and displayed in the datasheet view. If I take out the checkbox from the query, it works perfectly fine. It's not liking the checkbox part b/c apparently I'm not using the correct syntax. How do you show a true or false in the VALUES part (non-SQL)? I know for string it's '" & someString& "' and a number it's " & someNum & ", but can't really find an answer when the value is a boolean.

  5. #5
    f15e is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2016
    Posts
    75
    I got it worked out. I had an issue in my subform and just used [FieldName] = '" & Me.MyCheckBoxControl & "'. Thanks for the responses!!

  6. #6
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Great that you worked it out.

    Yes I see they are reserved words but that's not my problem. I could change them but at this point they work fine without errors
    Well... OK, good luck with that. They are called reserved words for a reason.

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

Similar Threads

  1. Replies: 14
    Last Post: 08-20-2015, 03:33 PM
  2. Ms access 2010 insert into syntax error
    By accessTenderfoot in forum Queries
    Replies: 13
    Last Post: 08-14-2015, 07:58 PM
  3. Replies: 14
    Last Post: 07-07-2015, 07:39 PM
  4. Access 2010 Checkbox & Validation Rules
    By mrmims in forum Access
    Replies: 1
    Last Post: 04-29-2014, 08:52 AM
  5. Access 2010 after insert
    By redja71 in forum Access
    Replies: 3
    Last Post: 06-18-2013, 10:00 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