Results 1 to 3 of 3
  1. #1
    jcc285 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2014
    Posts
    70

    Unhappy Include the value of a boolean field in SQL Insert string

    I have a form which has three variables, 2 text box string variables (strMembershipType & strIsType) and one checkbox boolean value (chkPayingMember) this can be True or False.


    These represent values in an underlying table, fields Membership_Type (text), Membership_Code(text), Paying_Member(True/False)

    Using data entered into the form I am trying to create an SQL INSERT string.

    strSQL = "INSERT INTO tbl_Members (Membership_Type,Membership_Code, Paying_Member VALUES ('" & strMembershipType & "','" & strIsType & "',WHAT GOES HERE)"

    I think I've tried every combination of single and double quote without success, all I want is for the last item to say True or False. It stubbornly refuses to do this constantly returning the variable name as a literal rather than a value.

    Help gratefully received

  2. #2
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,445
    Boolean is a number (True/False, Yes,No, -1,0), so no quotes required


    .... & strIsType & "'," & True & ")"

    or

    .... & strIsType & "'," & -1 & ")"

    or

    .... & strIsType & "'," & chkPayingMember & ")"


    note that chkPayingMember must not be null otherwise you will get an error

  3. #3
    jcc285 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2014
    Posts
    70
    Thank you, the third option is what I wanted. Can't believe I didn't try that!! Ah well, end of a long day.
    I will trap a Null value before creating the string.
    Many thanks

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

Similar Threads

  1. Replies: 3
    Last Post: 03-17-2016, 12:46 PM
  2. Error on INSERT INTO string built with VBA
    By sstiebinger in forum Queries
    Replies: 4
    Last Post: 11-30-2015, 03:07 PM
  3. Replies: 2
    Last Post: 04-05-2015, 06:06 PM
  4. Include zero after decimal in text string
    By inhops in forum Queries
    Replies: 3
    Last Post: 08-14-2013, 03:02 PM
  5. Replies: 2
    Last Post: 05-18-2013, 08:58 PM

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