PDA

View Full Version : Application.run for dynamic procedures not working



Movian
04-28-2015, 08:44 AM
Hey,

I have after update events set for each text box and combo box on a form and I have built a sub that I can call that I am trying to get to trigger the after update procedure for each combo box and text box on the form but it doesn't seem to be working.

the sub that should call the sub procedures appears to be generating the name of the procedure correctly but the code never actually enters the sub when I try and trigger it with application.run (name)

any thoughts?


public sub CheckFields()
Dim ctrl As Control
Dim name As String
On Error Resume Next
For Each ctrl In Me.Controls
If Not ctrl.ControlType = acLabel And Not ctrl.ControlType = acCheckBox Then
name = ctrl.name & "_AfterUpdate"
ctrl.SetFocus
Application.Run (name)
End If
Next
end sub

Private Sub ANTICOAGULANT_TYPE_AfterUpdate()
Select Case Me.ActiveControl
Case 0 To 6
Me.Controls(Me.ActiveControl.name).BackColor = HEXCOL2RGB("#FFFFFF")
Case Else
MsgBox "Invalid option selected, please select a value that is valid for a VQI submission", vbExclamation, "Non VQI Value"
Me.Controls(Me.ActiveControl.name).BackColor = HEXCOL2RGB("#ED1C24")
End Select
End Sub

jonh
04-28-2015, 11:58 AM
Normally you would put the code in a standard module, so you can call it from anywhere


Public Sub evthdlr(ParamArray s())
Select Case Join(s, "_")
Case "command0_click", "command1_click"
Debug.Print "Event", s(1), "from", s(0)
End Select
End Sub


Private Sub Command0_Click()
evthdlr ActiveControl.Name, "Click"
End Sub


Private Sub Command1_Click()
evthdlr ActiveControl.Name, "Click"
End Sub