Share via

Access: Formatting Yes/No input for INSERT INTO

Anonymous
2015-11-12T18:33:15+00:00

I am trying to build an SQL string to INSERT data into a table which has a Yes/No field.  What is the syntax for encapsulating the value retrieved from a Userform checkbox into the SQL command?

The string I have is as follows.  Code3 is a value returned from a userform checkbox and is either true or false.  Code-3 is the Yes/No field in the table.

strSQL = "INSERT INTO Sortie(Tail_Number, Flight_Number, Code-3) VALUES ('" & TailNumber & "'," & FlightNumber & " & Code3 & ");"

Thanks,

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Duane Hookom 26,825 Reputation points Volunteer Moderator
2015-11-12T19:07:18+00:00

You have a field with a name Code minus 3 and seem to be missing a required comma.

Try:

strSQL = "INSERT INTO Sortie(Tail_Number, Flight_Number, [Code-3]) VALUES ('" & TailNumber & "'," & FlightNumber & "," & Code3 & ");"

Was this answer helpful?

0 comments No comments

6 additional answers

Sort by: Most helpful
  1. Anonymous
    2015-11-12T19:05:36+00:00

    I've tried ' ' around the Code3, I've tried # # around it, and I've tried nothing around it.  None of these has worked thus far.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2015-11-12T18:55:07+00:00

    Try with:

    strsql = "INSERT INTO Sortie(Tail_Number, Flight_Number, Code-3) VALUES ('" & TailNumber & "'," & FlightNumber & "," & Code3 & ")"

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2015-11-12T18:44:31+00:00

    Howdy:

    I have tried True as a string, as a Boolean and as and Integer.  Nothing works.

    I know strings go in between 'single' quotes, and dates go between #date# hashtags. Is there a special character that needs to surround the Boolean VALUE?

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2015-11-12T18:39:01+00:00

    Hi,

    try with True/False (-1 or 0)

    Minno

    Was this answer helpful?

    0 comments No comments