Problem with invalidateControls

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • alainb
    New Member
    • Jun 2010
    • 2

    #1

    Problem with invalidateControls

    am trying to get my nav buttons up to date every time I move to another record, my XML file is good and my call back related to them are also good.
    The problem is when I load my main form, I get an error91 object variable or with block not set. I tried to create a small sub to specially invalidate specific controls but it works only when my main form is loaded again.
    So I want to know on how I can solve this, here is what I did so far:

    <customUI xmlns="http://schemas.microso ft.com/office/2006/01/customui" onLoad="OnLoadR ibbon">
    <ribbon startFromScratc h="true">
    <tabs>
    <tab id="tabHome" label="Home">

    <group id="grpNews" label="News">
    <labelControl id="lblWelcome " getLabel="onGet Label"/>
    <labelControl id="lblToday" getLabel="onGet Label"/>
    </group>

    <group id="gprTools" label="Tools">
    <button idMso="Spelling Access" label="Spelling " size="large"/>
    <button idMso="FindDial og" label="Find" size="large"/>
    <toggleButton idMso="FiltersM enu" label="Filter" size="large"/>
    </group>

    <group id="grpNav" label="Navigati on">
    <box id="boxNavLbl" boxStyle="horiz ontal">
    <labelControl id="lblNav" getLabel="OnGet Label"/>
    </box>
    <box id="boxNav" boxStyle="horiz ontal">
    <buttonGroup id="bg1">
    <button id="NewLease" imageMso="GoToN ewRecord" onAction="OnNav igateRecord" getEnabled="OnG etNavEnabled"/>
    <button id="MoveFirst" imageMso="MailM ergeGoToFirstRe cord" onAction="OnNav igateRecord" getEnabled="OnG etNavEnabled"/>
    <button id="MovePrev" imageMso="MailM ergeGoToPreviou sRecord" onAction="OnNav igateRecord" getEnabled="OnG etNavEnabled"/>
    </buttonGroup>
    <editBox id="txtJump" sizeString="000 000" onChange="OnCha ngeRecord" getText="OnGetT ext"/>
    <buttonGroup id="bg2">
    <button id="MoveNext" imageMso="MailM ergeGoToNextRec ord" onAction="OnNav igateRecord" getEnabled="OnG etNavEnabled"/>
    <button id="MoveLast" imageMso="MailM ergeGotToLastRe cord" onAction="OnNav igateRecord" getEnabled="OnG etNavEnabled"/>
    <button id="DelLease" imageMso="Recor dsDeleteRecord" onAction="OnNav igateRecord" getEnabled="OnG etNavEnabled"/>
    </buttonGroup>
    </box>
    </group>

    <group id="grpExit" label="Exit">
    <button id="cmdCloseDat abase" label="Close Database" imageMso="FileC lose" size="large" onAction="onBut tonCommand" supertip="Close current database only."/>
    <button id="cmdExitData base" label="Close And Exit" imageMso="Print PreviewClose" size="large" onAction="onBut tonCommand" supertip="Exit the database and close Access."/>
    </group>

    <group id="grpAbout" label="About">
    <button id="cmdHelpAbou t" label="About" size="large" imageMso="Help" onAction="onOpe nFormEdit" tag="frmAbout" supertip="View the About form."/>
    </group>
    </tab>

    </tabs>
    </ribbon>
    </customUI>

    my module where I keep callbacks
    Public gobjRibbon As IRibbonUI

    Public Sub OnLoadRibbon(ob jRibbon As IRibbonUI)
    Set gobjRibbon = objRibbon

    'to refresh, or invalidate all controls in the Ribbon
    If (Not gobjRibbon Is Nothing) Then
    gobjRibbon.Inva lidate
    End If
    End Sub

    Public Sub OnNavigateRecor d(ctl As IRibbonControl)
    'to allow user to navigate thru records
    Dim rec As AcRecord

    Select Case ctl.ID
    Case "MoveFirst"
    rec = acFirst
    Case "MovePrev"
    rec = acPrevious
    Case "MoveNext"
    rec = acNext
    Case "MoveLast"
    rec = acLast
    End Select

    DoCmd.GoToRecor d , , rec

    If (Not gobjRibbon Is Nothing) Then
    ' invalidate the nav label
    gobjRibbon.Inva lidateControl "lblNav"
    End If
    End Sub

    And my main form current event:
    Private Sub Form_Current()
    On Error GoTo ErrorHandler_Er ror

    'invalidate controls to keep in sync with record movement
    gobjRibbon.Inva lidateControl "lblNav"
    gobjRibbon.Inva lidateControl "MoveFirst"
    gobjRibbon.Inva lidateControl "MovePrev"
    gobjRibbon.Inva lidateControl "MoveNext"
    gobjRibbon.Inva lidateControl "MoveLast"
    ............... ..........
    ............... .........

    End sub

    I also tried calling my invalidate thru a custom function but still get the same result.
    I understang that my gobjRibbon is declared as a global variable, my other callbalck that require gobjRibbon are all working just fine, I do not need to declare it again
    but when it come to my main form, I get an error

    Any help is greatly appreciated since I have been on that problem for the past 2 days
    Thanks
  • jimatqsi
    Moderator Top Contributor
    • Oct 2006
    • 1293

    #2
    Give us the big picture. What do you mean, "my main form"? What is the main form, what is the subform, how are they interacting together?

    You said "but it works only when my main form is loaded again." so I'm wondering, is the main form being closed at some point?

    Also, please use code tags. You do that by clicking the "#" button before you start typing code, or type your code, then highlight it, and the click the "#" button.

    Jim

    Comment

    • alainb
      New Member
      • Jun 2010
      • 2

      #3
      My main forms is form being loaded at first, this form has only 1 subform attached to it(only 7 text field on it, linked as master/chield), all other forms are being opened as popups from command button so the information displayed is related to the curernt record on the main form. I only use 1 ribbon for all of my forms, right now, the popups do not display any ribbons at all because I do not need them, they are just data entry forms.
      The main forms is never being close unless you want to go to another section of the program like financials or reports, accessible from the switchboard.

      My entire process goes like this:
      once the ribbon vartiable is loaded, it call the onGetLabels to populate 3 text field on the first group, all OK, then it call onGetNavEnable to peoperly set my nav bottons in a separate group, then call the onGetLabel to populate the text field with the qty of current filtered record, then the main forms current event kicks in and the error is displayed. I do have a function being called from the current event of the main form to update the nav controls when moving to another record.
      Unless I am mistaken about the process of ribbon loading, that is the way it goes.

      This is the first time I use this site so I am not sure by waht you mean by using code tags, is it when I post code here so it can be clearer ?

      Many Thanks
      Al

      Comment

      Working...