Results 1 to 7 of 7
  1. #1
    PoorCadaver is offline Advanced Beginner
    Windows XP Access 2000
    Join Date
    Oct 2011
    Posts
    68

    How to use checkbox when column > 0?

    Hi!

    As the title inicates, I would like to know how to make a checkbox indicade when there is something typed in a column.

    Example:
    I have a table containing books with columns such as title, autor, etc. And I also have a column "notes" where I can make comments about the book.


    But when I'm printing out the table in a form or report, I would just lite to indicate that there is something written about the book, and not write out the whole comment.

    So how do I tell my checkbox (or other indicator sugestions) to indicate when lengt of column > 0?

    Thanks

    Jonas

  2. #2
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    You can create a query on the Table and add a field to it something like this:

    Code:
     
    HasNotes: IIf(Len(Trim([Notes]))>0,"Has Notes","No Notes")
    The [Notes] is where you would put the name of your field that has notes.

    Then you can have the 'HasNotes' field from the Query on your Form or Report.

    You can put whatever you want in place of "Has Notes" and "No Notes".

    Hope this helps!

  3. #3
    PoorCadaver is offline Advanced Beginner
    Windows XP Access 2000
    Join Date
    Oct 2011
    Posts
    68
    Thanks for the answer, but I'm still not so good with Access yet =) Will you please develop a little more?

  4. #4
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    Were you able to create the 'HasNotes' field in the query as I suggested?

    That would be the starting point.

    Once you have that query going with the HasNotes field, you have a couple of options.

    1. If you are creating a Report, base the report on the query that has the 'HasNotes' field. When you run the report, the HasNotes column will say whether a particular book has comments or not.

    2. If you want a checkbox on a Form to be checked if there are comments:

    First - make sure your Form has the check box on it.

    My example has:
    A checkbox named 'Check11'.
    I want Check11 to be checked when the HasNotes field says "Has Notes" - but NOT checked when there is anything else in there.

    Steps:
    1. Open the Form in design mode.
    2. Open the Property Sheet.
    3. Click the Events tab.
    4. Click the elipsis [...] to the right of Form Current.
    5. Choose 'Code Builder'.

    Here is my code:

    Code:
     
    Private Sub Form_Current()
    Dim strNotes As String
     
    Me.HasNotes.SetFocus
    strNotes = Me.HasNotes.Text
     
    Select Case strNotes
        Case "Has Notes"
            Me.Check11.SetFocus
            Me.Check11.Value = True
        Case Else
            Me.Check11.Value = False
    End Select
     
    End Sub
    Whenever the user is navigating through the records on the Form, if the 'HasNotes' field says "Has Notes" - the check box is checked - otherwise the check box is unchecked.

    I hope this helps.

  5. #5
    PoorCadaver is offline Advanced Beginner
    Windows XP Access 2000
    Join Date
    Oct 2011
    Posts
    68
    I'm affraid I wasn't able to do that =( I thought I could but it seems like i missunderstood you or something...
    I have hte field "HasNotes" in my table, but not the query. Which fields do I need to use in the query?

  6. #6
    PoorCadaver is offline Advanced Beginner
    Windows XP Access 2000
    Join Date
    Oct 2011
    Posts
    68
    I have tried som stuff and I don't understand why I have to make a query to make it work?
    It feels like it don't need to be that complicated. I'm looking for something like:

    IF strlen(Notes) > 1
    Check11 = true

    Or am I completely wrong?

  7. #7
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    This:
    I would just lite to indicate that there is something written about the book, and not write out the whole comment.
    . . . is why I suggested the query.

    You said you didn't want the whole comment to show.
    That means you would not be using that field on your Form. No?

    So . . . if 'HasNotes' is NOT going to be on your Form - what WILL be on your Form to tell you whether the book does - or does not - have comments?

    Looking at your code:
    IF strlen(Notes) > 1
    Check11 = true
    . . . where are you getting your "(Notes)" from to do the strlen(Notes)?
    How are you bringing that value [for the record on the Form] from your table INTO your Form?

    Whatever is in HasNotes has to be available to the Form if you want to use it to determine whether to turn your check box on or off - right?

    OR
    You'll have to write code that:
    1. Reads the record on the Form,
    2. Finds the matching record in your Table,
    3. Gets the 'HasNotes' string from the Table into a variable,
    4. Perform the length function on the string,
    5. If it is greater than 0 - then turn the check box to checked,
    6. If it is not greater than 0 - then turn the check box to NOT checked.

    Another thing you can try is to put the 'HasNotes' field on the Form - but make the Visible Property false.
    THEN - you can use the length function on it.

    What I was suggesting is not complicated, really.
    If you can post a copy of your DB here - I can show you how.

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

Similar Threads

  1. Replies: 3
    Last Post: 09-28-2011, 04:29 PM
  2. Replies: 1
    Last Post: 08-18-2011, 08:35 AM
  3. sales DB selecting column and column range
    By pher77 in forum Queries
    Replies: 3
    Last Post: 06-11-2011, 04:04 PM
  4. Replies: 1
    Last Post: 03-14-2011, 10:04 AM
  5. Replies: 1
    Last Post: 04-15-2010, 02:07 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