Running a Subprocedure using a variable

SyntaxSocialist

Registered User.
Local time
Today, 12:00
Joined
Apr 18, 2013
Messages
109
I'm trying to emulate a behaviour in Access that I see a lot on web forms: you click out of the active control (into blank space, not another control) and the form fields update appropriately.

So I want my users to be able to click on the white space on a form I've built and have that trigger an update event based on the active control. In my case, it only applies to textboxes.

Here's what I've got. The red code is where I'm stuck. I think the Run method is what I'm looking for, but I'm having a hard time figuring out how to use it properly...

Code:
Private Sub Detail_Click()
    
    Dim strCall As String
    strCall = Me.ActiveControl.Name & "_AfterUpdate"
        
    If Me.ActiveControl.ControlType = acTextBox Then
        If Me.ActiveControl.AfterUpdate <> "" _
            Or IsNull(Me.ActiveControl.AfterUpdate) = True Then
                [B][COLOR="Red"]Access.Application.Run ("Private Sub " & strCall)[/COLOR][/B]
        End If
    End If

End Sub
 
I think this what you are trying to do and the event procedures will need to be Public:-

Code:
Private Sub Detail_Click()
        
    If Me.ActiveControl.ControlType = acTextBox Then
        If Me.ActiveControl.AfterUpdate = "[Event Procedure]" Then
            CallByName Me, Me.ActiveControl.Name & "_AfterUpdate", VbMethod
        End If
    End If

End Sub

Chris.
 
I think this what you are trying to do and the event procedures will need to be Public:-

Code:
Private Sub Detail_Click()
        
    If Me.ActiveControl.ControlType = acTextBox Then
        If Me.ActiveControl.AfterUpdate = "[Event Procedure]" Then
            CallByName Me, Me.ActiveControl.Name & "_AfterUpdate", VbMethod
        End If
    End If

End Sub

Chris.

Intriguing.

Sorry for the delay. Weekend, etc., etc.

Seems promising, but it's spitting out an application-defined or object-defined error...
 
Did you make the after update events Public?

Chris.
 
Did you make the after update events Public?

Chris.

Well that was embarrassing...

Yup, that did the trick.

I realized that all the textbox AfterUpdate events called the same procedure, so I just cut out the middle man and called that by name instead.

I'm having another issue now. It's unrelated, though, and I think I can figure it out. It seems that the code is running too fast for the application to keep up and needs a split second to process. It spits out an "invalid operation" error, but only when it runs on its own--not when I step through.
 
To say for sure, I would need to see a copy of the database in Access 2003 version.

As a pure guess:
Clicking on the detail section may not save changes made to a Text Box.

In fact, if one of the Text Boxes is still the Active Control then its After Update event would not have fired and you might need to use its Text property not its Value (default) property.

But that’s a pure guess and I would need to see the database.

Chris.
 

Users who are viewing this thread

Back
Top Bottom