Results 1 to 15 of 15
  1. #1
    accessnewb is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2011
    Location
    New York, NY
    Posts
    116

    Clearing a boolean flag

    Hi,
    I have a search form and 2 buttons in it - one to search in table view and one to search in form view. In the search results page, there is an item no field and when I click on the field, the corresponding details for that particular item opens up in another form. So far so good.



    So now I want the item No to be a hyperlink only in table view and not in form view. So I did some vb code to achieve that (I think the code is very crude, I am not the world's greatest programmer)

    Code:
     
     
    Public gblnHyperlink As Boolean 'Declare a global variable
     
     
    Dim blnHyperlink As Boolean 'Declare a variable in the general declarations section in the search form
     
    Private Sub searchForm_Click()
    blnHyperlink = False
    gblnHyperlink = blnHyperlink
    End Sub
     
    Private Sub searchTable_Click()
    blnHyperlink = True
    gblnHyperlink = blnHyperlink
    End Sub
     
     
    Private Sub Form_Load() 'In the load event of the search result form
    If gblnHyperlink = true Then
    Me.FPItem.IsHyperlink = True
    Else
    Me.FPItem.IsHyperlink = False
    End If
    End Sub
     
    Private Sub Item_Click() 'In the click event of the textbox in the search results form
    If Me.ItemNo.IsHyperlink = True Then
    DoCmd.OpenForm "F_Hyperlink", , , "ItemNo='" & Me.ItemNo & "'", , acDialog
    Else
    Me.txtTemp.Value = 1 'Dummy variable I set. Cos if the else part is left blank then it always shows as hyperlink
    End If

    Now the problem is, the boolean value is set properly only the first time the search results form loads. It is not set the consecutive times. For example, if I want to open the results in table view the first time and I click on the 'table view' button, then the ItemNo is displayed as a hyperlink and I can click on it. But without closing the search results page, if I click on 'form view' button, then the ItemNo is displayed as a hyperlink .

    I know I need to clear the flag, but not sure how. Anyone help me on this?

  2. #2
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    I'm not sure if this is what you're asking, but if you want to reset a boolean - that is
    change it from True to False Or From False to True, you can say

    blnField = Not blnField


    Not sure if this applies.

  3. #3
    accessnewb is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2011
    Location
    New York, NY
    Posts
    116
    umm, nope that doesn't work. The global boolean value I assigned needs to change based on button clicks. But it is changing only on load of the form and the button click doesn't affect the global boolean value. Please check the code and let me know where I went wrong.

  4. #4
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    The global boolean value I assigned needs to change based on button clicks.
    Well in the On Click event of the Button involved to change the gbln, since if can only change T-F or F-T, use
    gbln = Not gbln

    There is no obvious reason why the global (gbln in my sample) would not be changed.

    Please show your button on click code also.

  5. #5
    accessnewb is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2011
    Location
    New York, NY
    Posts
    116
    The onClick code is copied in my original message. Anyway, here is the code again:

    Code:
    Private Sub Item_Click() 'Dummy variable I set. Cos if the else part is left blank then it always shows as hyperlink
    End If
    
    If Me.FPItem.IsHyperlink = True Then
    DoCmd.OpenForm "F_ProductsHyperlink", , , "FPItem='" & Me.FPItem & "'", , acDialog
    Else
    Me.txtTemp.Value = 1
    End If
    End Sub

  6. #6
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    Where is the button click event code?

  7. #7
    accessnewb is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2011
    Location
    New York, NY
    Posts
    116
    umm, oops! that is also there in the original code. Will copy it again. I thought u meant the hyperlink click code. My bad!

    Code:
    Private Sub searchForm_Click() 'code when I click on the search 'form view' button in the search page
    blnHyperlink = False
    gblnHyperlink = blnHyperlink
    'blah blah code for the search criteria. No issues with this
    End Sub
     
    Private Sub searchTable_Click() 'code when I click on the search 'table view' button in the search page
    blnHyperlink = True
    gblnHyperlink = blnHyperlink
    'blah blah code for the search criteria. No issues with this
    End Sub

  8. #8
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    Quote Originally Posted by accessnewb View Post
    umm, oops! that is also there in the original code. Will copy it again. I thought u meant the hyperlink click code. My bad!

    Code:
    Private Sub searchForm_Click() 'code when I click on the search 'form view' button in the search page
    blnHyperlink = False
    gblnHyperlink = blnHyperlink
    'blah blah code for the search criteria. No issues with this
    End Sub
     
    Private Sub searchTable_Click() 'code when I click on the search 'table view' button in the search page
    blnHyperlink = True
    gblnHyperlink = blnHyperlink
    'blah blah code for the search criteria. No issues with this
    End Sub

    You said in earlier post
    Code:
    The global boolean value I assigned needs to change based on button clicks
    .
    So within the button click event you need to insert code to do that

    - if gblnHyperlink is the global boolean value, then

    gblnHyperlink = NOT gblnHyperlink will change its value


    INsert this line

    gblnHyperlink = NOT gblnHyperlink

  9. #9
    accessnewb is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2011
    Location
    New York, NY
    Posts
    116
    OK, at the expense of sounding totally dumb, do I insert this code just before end sub? Cos I did that once and there seemed to be no change

  10. #10
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    What do you want to happen when a button is clicked?

    For a test you could take this code
    Private Sub searchForm_Click() 'code when I click on the search 'form view' button in the search page
    blnHyperlink = False
    gblnHyperlink = blnHyperlink
    'blah blah code for the search criteria. No issues with this
    End Sub
    and adjust it as follows

    Private Sub searchForm_Click() 'code when I click on the search 'form view' button in the search page

    Msgbox "A - gblnHyperlink is " & gblnHyperlink
    gblnHyperlink = not gblnHyperlink
    Msgbox "B - glblnHyperlink is " & glbblnHyperlink

    blnHyperlink = False
    gblnHyperlink = blnHyperlink
    'blah blah code for the search criteria. No issues with this
    End Sub
    to show the effect of the reset code.

    And then we can look at the logic of your code

  11. #11
    accessnewb is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2011
    Location
    New York, NY
    Posts
    116
    Sorry if I haven't made myself clear. I have 2 buttons on the search form. One button opens up the search result form in 'form view' and the other button opens up the search result form in 'table view'. In the search results form, there is a field called ItemNo and I want the field to be a hyperlink only when the form is opened in 'table view'.

    In the code, the global boolean value is asisgned only when the user clicks the button for the first time. The consecutive times have no effect. For example, I click the 'table view' the first time then the global boolean value is assigned 'true' and the search results opens up properly with the hyperlink, but without closing the search result if I click on form view, then the hyperlink is displayed (I don't want it to be displayed).

    So basically the global value needs to be reassigned on each button click, but it is assigned the first time the button is clicked and is reassigned only if I close the search results page.

    So without closing the search results page, the global value needs to be reassigned based on the button click.

    Sorry for the long winded story. I wanted to make myself clear. (the Not boolean does not work)

  12. #12
    accessnewb is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2011
    Location
    New York, NY
    Posts
    116
    umm, anyone?

  13. #13
    accessnewb is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2011
    Location
    New York, NY
    Posts
    116
    @orange: I tried your code with the msgbox and this is what happens. When I first click 'table view', then the first msgbox is true and the 2nd msgbox is false. If I click on the 'form view' (without closing the search results), then the first msgbox is true and the 2nd msgbox is false.

    If I close the search results and then click on 'form view', then the first msgbox is false and the 2nd msgbox is true.

  14. #14
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    Yes, the code sample I gave just changed the value of the gblnHyperlink and presents a message before and after the value has changed. My intent was to assist you with other logic once you understood how the global boolean value was changed.

    Based on your posts I thought you wanted to change the value of GblnHyperlink when the button was clicked. However, based on your explanation, I now am quite confused on what it is you're wanting to happen. I am not following what it is you are trying to do.
    Hopefully someone else reading the thread can help.

  15. #15
    accessnewb is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2011
    Location
    New York, NY
    Posts
    116
    Can anyone help me out on this?

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

Similar Threads

  1. Boolean Comparison Not Working
    By Rawb in forum Programming
    Replies: 4
    Last Post: 09-03-2010, 09:17 AM
  2. Unique Values and Boolean Fields
    By Triad in forum Forms
    Replies: 1
    Last Post: 07-15-2010, 06:28 PM
  3. Using an Update query to autofill boolean
    By Fuzzyjello in forum Queries
    Replies: 13
    Last Post: 06-09-2010, 10:27 AM
  4. clearing a form
    By macsterling in forum Forms
    Replies: 0
    Last Post: 07-31-2008, 10:38 AM
  5. How to query boolean values from table
    By kevdmiller in forum Queries
    Replies: 2
    Last Post: 11-30-2006, 07:41 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