Ask Your Question
0

Modify a macro to deactvate a list box

asked 2017-10-26 10:02:20 +0200

asteroid gravatar image

With this macro, I can activate or deactivate a List Box using a button. How can I modify it to deactivate the List Box when the content of a text field is different from "D"?

Thank you

Sub S_deactivate_Listbox(event)
oButton = event.source.model
oForm = oButton.Parent
oLstbox = oForm.getbyname("lst_FK_ID_P")
if oButton.Label ="activate Listbox" then
    oButton.Label = "deactivate Listbox"
    oLstbox.Enabled = true
else
    oButton.Label = "activate Listbox"
    oLstbox.Enabled = false
endif

End Sub

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
0

answered 2017-10-26 16:05:15 +0200

Ratslinger gravatar image

Hello,

As opposed to "modifying" you routine, it's more of just using the same concept. Instead of checking the Button status, now you just check the value in the text box:

Sub CheckTextBox(oEvent)
    oForm = oEvent.source.model.Parent
    oLstbox = oForm.getbyname("lst_FK_ID_P")
    sValue = oForm.getbyname("YOUR_TEXT_BOX_NAME").Text
    if sValue = "D" then
        oLstbox.Enabled = true
    else
        oLstbox.Enabled = false
    endif
End Sub

Just attach this to the Changed event of the text box.

Also, in your routine, instead of checking a long string, just check the list box status:

if oLstbox.Enabled  then
    oButton.Label = "activate Listbox"
    oLstbox.Enabled = false
else
    oButton.Label = "deactivate Listbox"
    oLstbox.Enabled = true
endif
edit flag offensive delete link more
0

answered 2017-10-26 17:35:36 +0200

asteroid gravatar image

Thak you, it works.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-10-26 10:02:20 +0200

Seen: 87 times

Last updated: Oct 26 '17