Full Version: Refresh A Form On Navagation Control
UtterAccess Forums > Microsoft® Access > Access Forms
ocoutrun
Hi there

I have a navigation Control on a form with 5 tabs. I'm using a color picker to change the forecolor of text boxes (up to 100 boxes) on the subforms on each navigation tab. This color is saved in a 'settings' table for future use. How do I 'refresh' the nav form to show the changed forecolor? If I simply change tabs and come back the color is changed but I need it to change after the user picks it.

Particulars

Main Form Name = BinMapping
NavPanel names = nav1house, nav2house, nav3ahouse, nav3bHouse and nav4House

Nav Panel Forms = 1House, 2House etc...

thanks for any help!
theDBguy
Hi. Are you using any code to change the color? If so, can you show us the code?
ocoutrun
Hi there

Here's the code on the main form(BinMapping)

CODE
Private Sub cmdChangeColor_Click()
Dim strColor As String
Dim dbs As DAO.Database
Dim rsSettings As DAO.Recordset
Dim vntControl As Control

Set dbs = CurrentDb

strColor = ChooseWebColor(strColor)

If Not IsNull(strColor) Then

    Set rsSettings = dbs.OpenRecordset("SELECT * FROM BinMapSettings")
    
    rsSettings.MoveFirst
    
    rsSettings.Edit
    
    rsSettings("Weightcolor") = strColor
    
    rsSettings.Update
    
    rsSettings.Close
    
    Set rsSettings = Nothing
    
End If



End Sub


In a separate Module:

CODE
Option Compare Database
Option Explicit

Declare Sub wlib_AccColorDialog _
  Lib "msaccess.exe" _
    Alias "#53" (ByVal Hwnd As Long, lngRGB As Long)


Public Function ChooseWebColor(DefaultWebColor As Variant) As String
  Dim lngColor As Long
  lngColor = CLng("&H" & Right("000000" + _
                  Replace(Nz(DefaultWebColor, ""), "#", ""), 6))
  wlib_AccColorDialog Screen.ActiveForm.Hwnd, lngColor
  ChooseWebColor = "#" & Right("000000" & Hex(lngColor), 6)
End Function
theDBguy
Hi. Thanks. There's still a piece of the puzzle that we're missing. The code you posted updates the table, but i don't see where we're updating the form. How exactly are you waiting the color to the form?
ocoutrun
Sorry for that. Here's the code to change the color...

CODE
Private Sub Form_Load()
Dim vntControl As Control
Dim strGrade, strColor As String

For Each vntControl In Me.Controls

    If vntControl.Tag = "Grade" Then
    
        'Debug.Print "Control Value= " & vntControl.Value
        strGrade = vntControl.Value
        
        If Not IsNull(strGrade) Or Not strGrade = "" Then
        
            strColor = DLookup("DisplayColor", "GrainCodes", "GCode= '" & strGrade & "'")
            
            'Debug.Print "&h" & Right(strColor, 6)
            
            vntControl.ForeColor = "&h" & Right(strColor, 6)
            
        End If
    
    End If

    If vntControl.Tag = "Weight" Then
    
        strColor = DLookup("WeightColor", "BinMapSettings")
    
        vntControl.ForeColor = "&h" & Right(strColor, 6)
    
    End If

Next vntControl

End Sub



it's the second part of the For/Next loop

this code is in each subform code. ie 1house, 2 house etc...
theDBguy
Thanks. Try adding a call to the form's Load event at the end of the change color Click event.
ocoutrun
Thanks for the reply

So, your saying call the Form_Load event for the subform - 1House from the main form - BinMapping. Not sure how to do that...?

Thanks
ocoutrun
After a little searching I found and tried this...

CODE
Private Sub cmdChangeColor_Click()
Dim strColor As String
Dim dbs As DAO.Database
Dim rsSettings As DAO.Recordset
Dim vntControl As Control

Set dbs = CurrentDb

strColor = ChooseWebColor(strColor)

If Not IsNull(strColor) Then

    Set rsSettings = dbs.OpenRecordset("SELECT * FROM BinMapSettings")
    
    rsSettings.MoveFirst
    
    rsSettings.Edit
    
    rsSettings("Weightcolor") = strColor
    
    rsSettings.Update
    
    rsSettings.Close
    
    Set rsSettings = Nothing
    
End If

Call Form("1House").Form_Load

End Sub



But I get 'Cannot find the referenced form 1House' error.

That is the name of the form...
theDBguy
Hi. Sorry. It's hard when you can't see the forms. I forgot we were talking about calling a subform's event. You can call another form's event if you declare it Public. As an alternative, you can just "reload" the subform by using the BrowseTo command to basically refresh the subform. It's like closing and reopening it. Hope that helps...
ocoutrun
Thanks for your help

That does 90% of what I want. I get the 'refresh' but if I was on say tab 3, it 'refreshes and goes back to Tab 1. I would think a simple 'What tab was I on' vari should fix that. I assume you can browseTo a form and choose a subform...?

Thanks
theDBguy
Yes, the BrowseTo should have some parameters that can tell which subform to refresh. I can't test it right now, but what did you use?
ocoutrun
For a quick test it was simply...

CODE
DoCmd.BrowseTo acBrowseToForm, "BinMapping"



That just reloads the main(BinMapping) and of course gives me the first tab preview which is 1House(Sub Tab1)

Just reading up on BRowseTo...not getting a good picture of what to use for BrowseTo Main.Sub
theDBguy
See if this blog article helps.
ocoutrun
Wow, did I ever cloud over on that one. iconfused.gif

I don't get the MainForm1.subForm1>Form1.subForm1 bit.

All I get is from that is "BinMapping.navconHouses>1House" which doesn't work...
ocoutrun
I tried this:

CODE
DoCmd.BrowseTo acBrowseToForm, "House1", "BinMapping.navconHouses>nav1House"


...doesn't work.
theDBguy
Hi. You might consider posting a copy of your db for us to try. Just a suggestion...
ocoutrun
Here's the dbase.

I've been trying a few things and can't figure it out.


Particulars:

Main form: BinMappings

Nav Control: navconHouses

navControl tab: nav1House

Form for nav1House: 1House
theDBguy
Hi. Thanks for posting your db. Either one of the following should work.

Me.NavigationSubform.SourceObject = Me.NavigationSubform.SourceObject

or

DoCmd.BrowseTo acBrowseToForm, Me.NavigationSubform.SourceObject, "BinMapping.NavigationSubform"

Hope that helps...
ocoutrun
Bang on what I needed

Thanks for your help!
theDBguy
Hi. You're welcome. Glad we could assist. Good luck with your project.
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.