Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms / May 2008

Tip: Looking for answers? Try searching our database.

Can a work-field utilize "On Change" code?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jimbo213 - 14 May 2008 19:29 GMT
I have six Yes/No check boxes which give values of -1 and 0 respectively.

When any is -1 "On" I turn a work field [TestInSystem] to -1 "On"
When all are off I turn the same work field [TestInSystem] to 0
That work field logic is working just fine.

I am having trouble setting visible=False/True for 2 controls based on the
value in this work field [TestInSystem]

I suspect that On Change won't work unless you manually change the
[TestInSystem] value - and it is changing behind the scene.

Here is the code I'm using:

Private Sub TestInSystem_Change()
'
If Me.TestInSystem = -1 Then           ' "Yes" condition
   Me.Text1169.Visible = True
   FrameStatusWAVE.Visible = True
   Else
   Me.Text1169.Visible = False         ' "No" condition
   FrameStatusWAVE.Visible = False
End If
'
End Sub

I'd appreciate a boot in the right direction.

Thanks for your reply & assistance.
Jimbo213
Steve Sanford - 15 May 2008 05:16 GMT
From HELP:

**Setting the value of a control by using a macro or Visual Basic doesn't
trigger this event for the control. You must type the data directly into the
control, or set the control's Text property.

So using code to set/change the value of [TestInSystem] won't work.... the
change event won't fire.

BTW, this:

If Me.TestInSystem = -1 Then           ' "Yes" condition
    Me.Text1169.Visible = True
    FrameStatusWAVE.Visible = True
    Else
    Me.Text1169.Visible = False         ' "No" condition
    FrameStatusWAVE.Visible = False
End If

can be shortened to two lines:

    Me.Text1169.Visible = Me.TestInSystem
    FrameStatusWAVE.Visible = Me.TestInSystem

This is how I might do it (one way...):

Private Sub Check0_AfterUpdate()
  Set_Visible
End Sub

Private Sub Check2_AfterUpdate()
  Set_Visible
End Sub

Private Sub Check4_AfterUpdate()
  Set_Visible
End Sub

Private Sub Check6_AfterUpdate()
  Set_Visible
End Sub

Private Sub Check8_AfterUpdate()
  Set_Visible
End Sub

Private Sub Check10_AfterUpdate()
  Set_Visible
End Sub

Sub Set_Visible()

 'TestInSystem is set to TRUE if the sum is < zero
 'TestInSystem is set to FALSE if the sum is = zero

  'this should be one line
  Me.TestInSystem = (Nz(Me.Check0, 0) + Nz(Me.Check2, 0) + Nz(Me.Check4, 0)
+ Nz(Me.Check6, 0) + Nz(Me.Check8, 0) + Nz(Me.Check10, 0)) < 0
 
 ' hide or show controls
  Me.Text1169.Visible = Me.TestInSystem
  FrameStatusWAVE.Visible = Me.TestInSystem

End Sub

Instead of hiding the controls, you might set the Enabled property:

  Me.Text1169.Enabled = Me.TestInSystem
  Me.FrameStatusWAVE.Enabled = Me.TestInSystem

That way, the field is still there but data cannot be entered. Sometimes it
is less confusing to have controls disabled and not appearing and disappearing

HTH
Signature

Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)

> I have six Yes/No check boxes which give values of -1 and 0 respectively.
>
[quoted text clipped - 26 lines]
> Thanks for your reply & assistance.
> Jimbo213
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.