Indirect reference to Textbox control method

  • Thread starter Thread starter James
  • Start date Start date
J

James

Hello,

I am using A2K and I have a sub that accepts a Textbox control as a
parameter, e.g.,

sub DoSomething(aTextboxCtl as textbox)

I would like to invoke the AfterUpdate method of that control from
within the sub but I do not know how to refer to the methods of that
control. Properties are easy (aTextboxCtl.backcolor, etc). If I was
referring to the textbox directly I could use
<textboxname>_AfterUpdate() to invoke its afterupdate.

Can anyone tell me the proper syntax to do such an indirect reference
to a method of a textbox (or if it is even possible)?

TIA,
James
 
Hi,


You can probably use CallByName( ) (available in VBA6, so, Access 2000
and later).


Hoping it may help,
Vanderghast, Access MVP
 
Hi,


Have you tried to change the access restricted by default, as private, to
public, for the method you call by name? Only the own code of the class can
call its private method.



Vanderghast, Access MVP


James said:
Hi Michel,
That was an excellent suggestion but unless I am doing something really
stupid (quite possible) it does not seem to work. I get a run-time error 438
(Object doesn't support this property or method). What I am trying to do is
really pretty simple:
A pushbutton sends the name of an associated Textbox control to another
Sub which calls a function to display a calendar. if the user selects a date
different than the one currently displayed in the textbox control passed as
the parameter I want to execute the Textbox's AfterUpdate just as though the
user had entered the new date directly into the textbox.
The pertinent code is as follows:

Private Sub cmdGetEEDate_Click()
x = txtEEDt.Value
DateChange txtEEDt
' I have commented the next 3 lines because I was hoping to do this in the Sub DateChange
'If x <> txtEEDt.Value Then
' txtEEDt_AfterUpdate
'End If
End Sub

Private Sub txtEEDt_AfterUpdate()
SetDateAndTimeCtrls Me.txtEEDt, Me.txtEETime, Me.EEDt
End Sub


Private Sub DateChange(aDateCtl As TextBox)

Dim x
Dim bRefresh As Boolean
x = glrDoCalendar(aDateCtl.Value)
If x > "" Then
bRefresh = True
If IsNull(aDateCtl.Value) = False Then
bRefresh = aDateCtl.Value <> x
End If
aDateCtl.Value = x
If bRefresh Then
' The following always generates the 438 error...
CallByName aDateCtl, "AfterUpdate", VbMethod
End If
End If
aDateCtl.SetFocus
End Sub

Of course, there are other ways to 'skin this cat' but it seemed to me
that I should be able make the Sub DateChange do exactly what I wanted and
save a little bit of code as well (There are, in fact, multiple such Textbox
and CommandButton controls on this particular form.)
 
Hi,


should have read your whole message. The procedure name if
"Form_AfterUpdate", not just "AfterUpdate". The CallByName requires the full
name.



Vanderghast, Access MVP
 
Hi,


Should not... Let me try... indeed, it works. So, let look at your code more
closely ...and yep, should be that: the code belong to the FORM, not to the
control (the control raised an event, and the FORM's code respond to that
event). Should be:

CallByName Me, aDateCtl.Name & "_AfterUpdate", VbMethod



assuming that this line of code occurs under the same form, else, don't use
Me but a valid reference to the form.



Hoping it may help,
Vanderghast, Access MVP

James said:
Hi again,

Actually, none of your suggestions work, I still continue to get the 438
run-time error. I have made the textbox's AfterUpdate method be Public and I
have specified both "AfterUpdate" and "txtEEDt_AfterUpdate" and none of this
makes a difference.
I noticed that you indicated using "Form_AfterUpdate" - there may be a bit
of confusion and perhaps I am attempting to do something that is not
possible: I want to invoke the AfterUpdate of the Textbox NOT the Form. Does
that make a difference?
 
Back
Top