Page 1 of 2 12 LastLast
Results 1 to 15 of 22
  1. #1
    PDilly is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jan 2019
    Posts
    78

    Form toggle button conditional colour change

    Hi guys

    my brain isn’t what it used to be!

    i have a form in which there is checkbox field. It receives its tick elsewhere. I have added a toggle button which shows the appropriate colour and caption when the form opens and displays a record. As I move through each record, the bottom changes colour to reflect the true/false condition of the checkbox. Shows red or green.
    the code for the colour is in the form's on current settings and reads thus:

    If WARN = 0 Then
    Me!Toggle333.Caption = "No Warnings Issued"
    Me!Toggle333.BackColor = RGB(0, 255, 0)

    Else

    'If WARN = -1 Then

    Me!Toggle333.Caption = "Warnings Issued"
    Me!Toggle333.BackColor = RGB(255, 0, 0)
    End If

    the on click property of the button itself is set to open another form, which it does.



    There are two minor things that I can’t crack; firstly when I click the button to go to the other form, the button turns blue and upon my return to my first form, remains blue. Even as the checkbox contion changes when scrolling through records. The caption does however change according to the record but the button now stays blue if it’s been clicked. I knoww this form stays open and that my second form opens over it.

    the second part of my problem is that my second form is controlled by a combo box, so when I open it, it has no record showing. It’s not the end of the world, but I would like it to be able to show info for the same record I was viewing in the first form.

    the two forms use separate tables as their record sources but share a record number. I think It’s just a question of circumventing the combo box. If I knew how...

    any my help would be most welcome

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    The second sounds like:

    http://www.baldyweb.com/wherecondition.htm

    I'm not clear on the sequence of for the first.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    Replace the toggle button with a regular (command) button as you are doing the (pseudo) toggling manually.

    As for your second problem simply provide the record id to to second form and requery:
    Code:
    Docmd.OpenForm " frmSecondForm"
    Form_frmSecondForm.cboFind=me.RecordID
    Form_frmSecondForm.Requery
    Cheers,
    Vlad

  4. #4
    PDilly is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jan 2019
    Posts
    78
    Thanks guys,

    button colour now functioning.
    I'll work on bringing up the right record tomorrow.
    I'm starting to remember how i did it in the past ��

  5. #5
    PDilly is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jan 2019
    Posts
    78
    Quote Originally Posted by PDilly View Post
    Thanks guys,

    button colour now functioning.
    I'll work on bringing up the right record tomorrow.
    I'm starting to remember how i did it in the past ��
    Hi guys,

    button is fully functional, no problems there. Record on second form displays exactly as it should.

    However, on the second I have an exit button which is just a macro to close the form, nothing more.

    whether that form and therefore the record, is updated makes no difference, when the second form closes, it returns me to the first form which is still in its original state. If a change has has been made using the second form, it is not reflected in the first form until I move to a new record and then back the original record.

    I'm guessing that I need a Refresh command somewhere to refresh the first form after the second form is closed. I’m just not sure where to put it, bearing in mind that under 90% of circumstances the user won’t need to use the second form and wouldn’t normally leave the first page when updating or adding records until the job is complete.

    i should add that the second form is accessed from both a main menu and the first form. So refreshing form one from the exit code of form two throws up an error.

    any further help most welcome

    many thanks
    PD

  6. #6
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    I think you want to add the refresh code on the unload event of the form two but checking if the first form is open.

    Just in case you don't already have it, here is a function I use:
    Code:
    Public Function isOpen(ByVal strFormName As String) As Boolean
    '=======================
    'creates IsOpen function
    '=======================
    Const conDesignView = 0
    Const conObjStateClosed = 0
    isOpen = False
    If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> conObjStateClosed Then
        If Forms(strFormName).CurrentView <> conDesignView Then
            isOpen = True
           
        End If
    End If
    End Function
    Cheers,
    Vlad

  7. #7
    PDilly is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jan 2019
    Posts
    78
    Quote Originally Posted by Gicu View Post
    I think you want to add the refresh code on the unload event of the form two but checking if the first form is open.

    Just in case you don't already have it, here is a function I use:
    Code:
    Public Function isOpen(ByVal strFormName As String) As Boolean
    '=======================
    'creates IsOpen function
    '=======================
    Const conDesignView = 0
    Const conObjStateClosed = 0
    isOpen = False
    If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> conObjStateClosed Then
        If Forms(strFormName).CurrentView <> conDesignView Then
            isOpen = True
           
        End If
    End If
    End Function
    Cheers,
    Vlad
    thank you Vlad
    I'll give that a whirl
    regards
    Pete

  8. #8
    PDilly is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jan 2019
    Posts
    78
    Well, I gave it a whirl but unfortunately, after a bit of testing I found that whilst form 1 is in the background it isn't loaded or open as I thought so the code worked but returned false.

    It's probably not worth the hassle as it's way out of my comfort zone but:

    Starting from cold.

    I have a main form which whatever the user does, he will end up back there. He can access form 2 directly from there and once his work is done, he will return by default to the main form, in which case the button colour issue is of no consequence because when form 1 is subsequently opened it will be the correct colour.

    If however form 2 is opened from form 1 with a given record in view, currently form 2 opens at the corresponding record the same ID in a differnet table. Thet's as it should be.. When form 2 is exited, the record (if one has been created) is saved in its table, form 2 closes and form 1 re-appears as it was left, at the same record. It's at that point that it would be useful for the button to change colour if a record was created or changed. That's determined by a checkbox on form 1 which is correctly updated when the form re-opens. the button just doesn't know it!!

    I have tried putting my working button colour code in a number of form 1's obvious On#### properties but nothing is persuading form 1 to update the button. Temporarily I have the code in the button click and Form 1's OnCurrent property and those two are doing what they should.
    I'm quite certain my brain is missing something!!!

    any further help would be most welcome
    PD

  9. #9
    PDilly is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jan 2019
    Posts
    78
    PS
    i used to be able to do this in my sleep. Now I just sleep...

    the nub of of what’s happening is that the record in view in form 1 may have been changed in the underlying table by form 2

    does this just need a requery somewhere but only if closing form 2 to return to form 1?

  10. #10
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    Put the code in a public sub in the first form. Call that sub from the OnCurrent on form 1 as needed and also call it from the unload event of the second form (maybe add a Forms!frmOne.Form.Refresh just before calling it).

    Cheers,
    Vlad

  11. #11
    PDilly is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jan 2019
    Posts
    78
    Quote Originally Posted by Gicu View Post
    Put the code in a public sub in the first form. Call that sub from the OnCurrent on form 1 as needed and also call it from the unload event of the second form (maybe add a Forms!frmOne.Form.Refresh just before calling it).

    Cheers,
    Vlad
    Hi Vlad, thank you for taking the time to help. I’m afraid that didn’t work either.

    i just had a thought. On form 1, The colour button is a recent add on but the checkbox has been there forever.
    perhaps the button colour code needs implanting somewhere in the checkbox properties rather than the form properties.

    bearing in mind that despite being in the underlying table of form 1, the checkbox is not actioned in form 1, only in form 2.

    If I’m right which checkbox On property might trigger the colour change?

  12. #12
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    Would you be able to upload a stripped down version of your db with just the two forms and the supporting tables (no sensitive data, just a couple of dummy records) and queries. If not maybe post the full code as you have it right now in each form (only the relevant one). Is the checkbox control called Warn on form 1 or does it have a different name than the bound field?
    You should at least use Me.Warn=0 in the code instead of just Warn=0.
    Cheers,
    Vlad

  13. #13
    PDilly is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jan 2019
    Posts
    78
    Hi Vlad,

    Thank you for your patience
    I've pared everything down to the bone and put it in a zipfile which hopefully will upload.
    Form1 is Member_entry, Form 2 Is Warnings_input.
    I use the warnings button on form 1 to access Form 2. but I can get there from the main form which I've stripped out. I'll worry about any errors arising from that.

    On form 2 you can add a warning or delete one then exit. that will create or delete an entry in the warnings table and check or uncheck WARN in the member details table.
    I've put a couple of entries in the warnings table.

    Don't look too deep into my coding. you will probably pull your hair out!!
    This version is prior to the start of our conversation so only has button colour code in Member_entry OnCurrent property

    If it's too much of a pain don't worry about it

    Many thanks
    PD
    Attached Files Attached Files

  14. #14
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    According to my computer, the zip file is empty.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  15. #15
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870

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

Similar Threads

  1. Replies: 4
    Last Post: 07-12-2017, 11:45 PM
  2. Change generic colour in Title on Form
    By mortonsafari in forum Forms
    Replies: 2
    Last Post: 03-20-2016, 06:11 PM
  3. Change Form Background Colour
    By Emma35 in forum Forms
    Replies: 11
    Last Post: 01-25-2016, 06:12 AM
  4. Replies: 3
    Last Post: 10-22-2015, 07:15 AM
  5. Change the colour of a form background
    By r_e_v_a_n_s in forum Forms
    Replies: 0
    Last Post: 11-15-2005, 03:39 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