Results 1 to 11 of 11
  1. #1
    Join Date
    Jun 2014
    Posts
    27

    Unanswered: Checkbox Problem

    Is there a way that I can make a checkbox that returns yes values when checked and both yes and no values when unchecked?

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    No
    a check box is a representation of a boolean value true/false, yes/no. Depending on the underlying data value it can also NULL.

    However it depends what you are trying to do. I suspect you are trying to set a filter in which case you can implement whatever you like
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Jun 2014
    Posts
    27
    What I am trying to do is basically disable this filter if I don't check the box, is there an easy way to do this?

  4. #4
    Join Date
    Jun 2014
    Posts
    27
    Can I do an On click event where I use a macro to stop the filter from happening or something like that?

  5. #5
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Yes code in after update event
    I'd rather be riding on the Tiger 800 or the Norton

  6. #6
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    what I'd think would be a better approach would be to have a command button in the forms header or footer which acts as a toggel button. press once to enable the filter, press again to disable the filter

    lets say your commandbutton is called cmdSetFilter...
    the initial state is show all records
    the caption for the command button is 'Set Filter'
    in its on click event:-
    Code:
    if cmd.SetFilter.caption = "Set Filter" then
      me.filter = "abooleancolumn = " & vbtrue 'i prefer to use the intrinsic vba constant
      me.filteron=true 'turn the filter on, the form shoudl automatically requery
      'me.refresh (or is it me.requery?) 'if the form doenst' then you may need this
      cmd.SetFilter.caption = "Remove Filter" 'set the caption for the next time round
    else
      me.filteron=false
      cmd.SetFilter.caption = "Set Filter"
    endif

    change the name of the command button to be the same as your
    abooleancolumn likewise
    it doenst' matter what captions you use as long as whatever you do is consistent

    the code finds if the command buttons text/caption is set filter, if so it applies a filter, otherwise it removes the filter
    I'd rather be riding on the Tiger 800 or the Norton

  7. #7
    Join Date
    Jun 2014
    Posts
    27
    Ok this looks good thanks, I understand what this does but for this line:
    me.filter = "abooleancolumn = " & vbtrue

    Do i put in the name of the column in my table for abooleancolumn and do i leave the quotations where they are, because i dont know what the( =" & vbtrue )does. Sorry I am not that savvy using the actual code

  8. #8
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    I dont know what is the name of your column that you want to filter on.
    so as suggested replace aBooleanColumn with the name of the column in your db
    vbtrue is as the code says an intrinsic vb/vba constant that always evalyates as true.
    The me .filter assigns the value of yhe following to the gorms filter property, but you have to activate the filter after assigning it, hence me.filteron = true
    I'd rather be riding on the Tiger 800 or the Norton

  9. #9
    Join Date
    Jun 2014
    Posts
    27
    Okay so here is what I put in but it isnt working I don't know if there was something else I had to replace in the code, I added an on click feature that makes it so that the button changes captions when clicked as well, does that make any of this code useless? Also I used setfilter as my button name
    If cmd.Setfilter.Caption = "Search By Hedging Program" Then
    Me.Filter = "Hedging Program = " & vbTrue 'i prefer to use the intrinsic vba constant
    Me.FilterOn = True 'turn the filter on, the form shoudl automatically requery
    'me.refresh (or is it me.requery?) 'if the form doenst' then you may need this
    cmd.Setfilter.Caption = "Don't Search By Hedging Program" 'set the caption for the next time round
    Else
    Me.FilterOn = False
    cmd.Setfilter.Caption = "Search By Hedging Program"
    End If
    Last edited by MCronin; 06-26-14 at 10:52.

  10. #10
    Join Date
    Jun 2014
    Posts
    27
    I stripped it down to this and because I already made the caption change function in the on click event of my setfilter button,

    If Me.Setfilter.Caption = "Search By Hedge Program" Then
    Me.Filter = "Hedging Program = " & vbTrue
    Me.FilterOn = True
    Else
    Me.FilterOn = False
    End If

    But it still just doesn't filter at all, both yes and no come up everytime i use my search

  11. #11
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    although Access allows you to use spaces between table and column names, that doesnt' mean you should. its against the SQL standard, and AFAIK virtually no other db does. There's actually no need to as you can set a caption/title property in the column design which makes a column name more human friendly.

    you can subvert the standard by delimiting column/table names with a pair of square brackets:_
    Code:
    SELECT [my table].[my column], [my table].[another column], [my table].[yet another column] from [my table]
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •