简体   繁体   中英

MS-Access Auto update form constantly to change visibility of a button

still strugling with an access database for a quality control system.

My last question was to have a button visibility and enable properties change to 0 if a condition wasnt met. I was able to do this with the following code:

Private Sub Form_Current()

Dim ok As Boolean
ok = Status.Value


Botão_Motores.Visible = ok
Botão_Motores.Enabled = ok

End Sub

But the problem now is that it only updates the status when i open and close the form, not when the Status field updates... My approach here, although im open to other strategies is to include somthing in the Change sub of the Status field to run the code in the form_current sub, is this possible or do i have to do it in another way? if so, how?

Thank you

Access has no event for a datachange in the form - just for the first time the user changed any data on the form (dirty) and for record change(current) and for datachanges in the controls (Dirty, Change, BeforeUpdate,AfterUpdate...)

You can make a procedure for that task and call it from Current and from the appropriate event (probably AfterUpdate) of the controls that should change the visibility of your button.

Private Sub ChangeMotorVisibility()
   Botao_Motores.visible=Status.value
End Sub

Private Sub Form_Current()
  ChangeMotorVisibility
End Sub

Private Sub Status_AfterUpdate()
  ChangeMotorVisibility
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM