Page 1 of 2 12 LastLast
Results 1 to 15 of 24
  1. #1
    twgonder is offline Expert
    Windows 10 Access 2016
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    714

    How use table search/replace on data type Yes/No?

    I just added an "Active" field to an existing table. I used the Yes/No data type and format in properties.
    All the records are set to no, or unchecked in the box that shows in the datasheet view.
    I want to change them No with replace to Yes.
    I've tried searching for no, 0, null, false, "" and the search part always comes back "...The search item was not found".



    How can I do this replace?
    What is the correct value to put in Default property to set to Yes for data type Yes/no)? (1, True and yes seem to work, I'm just not sure which is better.)

  2. #2
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    To set all or some to Yes/True, run an update query as this is not a replace issue. Y/N fields don't usually provide much in the way of useful data. Depending on what the field is for, you might be better off with a date field. Then a field such as InActiveDate with no date says it is Active, and one with a date not only says it is inactive, it tells you when as well.
    Perhaps review
    http://allenbrowne.com/NoYesNo.html
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,157
    -1 is the actual value that Access will use for Yes/True

    In the immediate window ;

    Code:
    ? CInt(true) 
    -1
    
    ? 0 = False
    True
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  4. #4
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,931
    probably over answering but here goes
    What is the correct value to put in Default property to set to Yes for data type Yes/no)?
    you can use -1, true or yes and 0, False or no - no advantage one way or the other - the underlying value will be -1 or 0. True, false, yes, no are just formats.

    You can even use the format property to show true/false (or yes/no) on number fields, include dates - sometimes useful when a user needs to know something has happened, but does not need to known when. You can even use a number field as controlsource to a checkbox, but I wouldn't recommend the control is editable.

    When evaluating a number for boolean, For numbers 0 is false, any other number is true

    ?cbool(0)
    False
    ?cbool(23456)
    True
    ?cbool(-1)
    True
    ?cbool(-234)
    True
    ?cbool(12.4)
    True
    ?cbool(#01/01/2022#)
    True


    which you can use to abbreviate code e.g.

    typically used

    if dcount("*","myTable")<>0 then

    but dcount can never be less than 0 so this will do
    if dcount("*","myTable")>0 then

    but dcount always returns a value and the value used in the evaluation so this will also work (assuming the then is to do something if there are records)

    if dcount("*","myTable")=true then

    or even simpler

    if dcount("*","myTable") then


    Note that yes/no fields cannot have a null default value (only unbound controls). You can specify it but it will default to 0 when the record is saved. If you need that functionality use a byte datatype combined with the format property

  5. #5
    twgonder is offline Expert
    Windows 10 Access 2016
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    714
    Quote Originally Posted by Minty View Post
    -1 is the actual value that Access will use for Yes/True
    Thanks for that, I haven't gotten into MS VBA yet. Funny, I've worked in several languages, I don't think true was ever -1.
    True was gt (yes, we had "gt" which meant >) 0. So, -0.00000001 would be false. 0.00000001 would be true. Zero obviously is false.
    Where is the ISO when standards are needed in Boolean logic? A whole byte for true? What happened to bits that I used for that? Having eight yes/no in a byte was fun.

  6. #6
    twgonder is offline Expert
    Windows 10 Access 2016
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    714
    I'm still looking for the way, if there is one, to do it with the Replace in table worksheet view.
    I'm not yet at the point of writing code or SQL to get 'er done.

  7. #7
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    UPDATE myTable SET myField = -1
    or
    UPDATE myTable SET myField = True

    Easy enough to do in the query design tool as well. If you need criteria so that the update affects only certain records, you need to add criteria to that. As written, all records would update. Update query does not produces a result set, so if you switch to datasheet view from the query design view, you cannot see the records that will be affected. However, you can see how many will be affected by counting the rows in the datasheet view.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  8. #8
    twgonder is offline Expert
    Windows 10 Access 2016
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    714
    Quote Originally Posted by Micron View Post
    Oh my goodness. I started with a query language, 45 years ago that wasn't SQL based. Just getting up to speed now. but that little tip there will save me a lot of future work. Good job pointing it out. Thanks!

  9. #9
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,931
    A whole byte for true?
    access doesn't have a bit datatype

  10. #10
    twgonder is offline Expert
    Windows 10 Access 2016
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    714

    The date solution works better

    I like making things easier on the user, but after reading the allenbrowne link...
    REALLY!!! 30 years and Access still has this problem?

    Click image for larger version. 

Name:	P1110426.JPG 
Views:	18 
Size:	159.2 KB 
ID:	48258
    Click image for larger version. 

Name:	P1110428.JPG 
Views:	18 
Size:	169.6 KB 
ID:	48257


    So far I've learned don't use lookup fields and don't use Yes/No fields.
    How many hours have I wasted on just these two? How many more await me?


    Anyways, to test the #2 post suggestion to use a date instead, I created this test db based on Allen Browne's example:

    YesNoBug.accdb

  11. #11
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,931
    I’ve never experienced a problem with yes/no fields so might be an idea you check before dismissing them

    And as I’ve mentioned before usually better to use a date field anyway as provides more information

  12. #12
    twgonder is offline Expert
    Windows 10 Access 2016
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    714

    How use these SQL statements safely and where?

    h
    Quote Originally Posted by Micron View Post
    UPDATE myTable SET myField = -1
    or
    UPDATE myTable SET myField = True

    Easy enough to do in the query design tool as well.
    So, I'm still getting back up to speed, where would we put those SQL statements if not in the query design tool?

    Now I'm off to change a few dozen Yes/No fields... Aggghhhh!

  13. #13
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,820
    Hi

    You would create an update query as shown below.

    The SQL View of the Update Query is also shown.
    Attached Thumbnails Attached Thumbnails Update.JPG   UpdateQuery.JPG  

  14. #14
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    The reason(s) for not using yes/no fields may not apply to you. Perhaps you will never need to migrate to sql server or the like. They are not necessarily bad to use. I probably would continue to use them in a lot of db's because the limitations won't apply to me. We were just trying to make you aware of the limitations. If you have a LOT of fields you think need to be altered, you can usually do with with sql and/or code.
    How many more await me?
    These will cover most of the common pitfalls:
    Normalization Parts I, II, III, IV, and V
    http://rogersaccessblog.blogspot.com...on-part-i.html
    and/or
    http://holowczak.com/database-normalization/

    Entity-Relationship Diagramming: Part I, II, III and IV
    http://rogersaccessblog.blogspot.com...ng-part-i.html

    How do I Create an Application in Microsoft Access?
    http://rogersaccessblog.blogspot.com...cation-in.html

    Naming conventions - http://access.mvps.org/access/general/gen0012.htm
    https://www.access-programmers.co.uk...d.php?t=225837

    What not to use in names
    - http://allenbrowne.com/AppIssueBadWord.html

    About Auto Numbers
    - http://access.mvps.org/access/general/gen0025.htm

    The evils of lookup fields - http://access.mvps.org/access/lookupfields.htm
    Table and PK design tips - http://www.fmsinc.com/free/newtips/primarykey.asp
    About calculated table fields - http://allenbrowne.com/casu-14.html
    About Multi Value Fields - https://www.isladogs.co.uk/multivalu...lds/index.html
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  15. #15
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    I'm probably also going into too much detail here ...

    Even if you upsize to SQL Server, you can still use yes/no (boolean) fields.
    In SQL Server these are called bit fields and unlike Access the field can have 3 possible values - true / false but it can also be null

    If you use this as a linked table in Access, you need to set the default value to either true or false & ensure there are no null values.
    Failure to do so will lead to Write Conflict Errors (isladogs.co.uk)

    The only other issue with boolean fields was that described by Allen Browne & I've never been affected by it
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 13
    Last Post: 03-22-2019, 04:09 PM
  2. Replies: 5
    Last Post: 08-26-2018, 07:54 PM
  3. Find & Replace Table source data?
    By Red Kenny in forum Access
    Replies: 3
    Last Post: 07-19-2018, 10:01 AM
  4. Possible to Import data and replace some, but not all, in table?
    By IncidentalProgrammer in forum Import/Export Data
    Replies: 2
    Last Post: 02-17-2015, 09:30 AM
  5. Replies: 5
    Last Post: 02-25-2013, 01:51 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