Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling the same function from multiple controls

Status
Not open for further replies.

Ascentient

IS-IT--Management
Nov 4, 2002
267
On my form I have 10 command buttons that delete the contents of the text boxes following them.
Each control is named delete1, delete2,...delete10.

In a Public function that is called from another control i verify some data and then if needed prompt the user to delete this "line". If they say "Yes" I want to call the onclick event of the appropiate delete button.

-Hierarchy-
Qty_AfterUpdate
-->Pub Fun CalcmatlineA
----->Call delete??_Click

I have tried the following code but I get the following error: Compile Error, Expected Sub, Function, or Property

Code:
Dim strCallProcedure As String
strCallProcedure = "delete" & Lineno & "_Click"
strCallProcedure
I can issue delete1_click and it works fine, but I need to be able to use Lineno as it identifies the control to call.
 
the line "strCallProcedure" doesn't do anything, as near as i can tell. it is just a variable name on a line by itself. i am not sure how you would get the string variable to be taken as a procedure name. maybe it would be easier to use a select case statement?

"Maturity is a bitter disappointment for which no remedy exists, unless laughter can be said to remedy anything."
-Vonnegut
 
Look at the Eval function in the help file.
You can use the Eval function to evaluate an expression that results in a text string or a numeric value.
 
So far know such luck.

This is what I have tested so far.

Run-Time error 2425 The expression you entered has an expression that can't be found.
Code:
 Dim strCallProcedure As String
 strCallProcedure = "delete" & Lineno & "_click()"
 Call strCallProcedure

I also tried the following and received: error 2482 can't find the name 'delete1_click' you entered into the expression.
Code:
 Dim strCallProcedure As String
 strCallProcedure = "delete" & Lineno & "_click"
 Call strCallProcedure

The procedure I want to call is the onclick procedure of a command button. (Just in case that was missed from my first post.
 
Yeah, and what about using the Eval function?

You can use the Eval function to evaluate an expression that results in a text string or a numeric value.

You can construct a string and then pass it to the Eval function as if the string were an actual expression. The Eval function evaluates the string expression and returns its value. For example, Eval("1 + 1") returns 2.

If you pass to the Eval function a string that contains the name of a function, the Eval function returns the return value of the function. For example, Eval("Chr$(65)") returns "A".

 
Sorry there were definitely typos in my previous post.

I do not believe the eval() will work for my case. I am not "returning" anything from the control.click event I want to activate.

I ended up modifying the code to call a different function which did what I need. (well, I had to tweak it some...)

Thanks for the help.
 
How are ya Ascentient . . .

Your post origination is out of context with accesss. [blue]Validation should be your primary goal here![/blue]
Am I tinking wrong or what?

Calvin.gif
See Ya! . . . . . .
 
A more general approach is to have each command button call a single procedure with the controls which the command button should "process". The SINGLE procedure can then reference the controls, htus obtaining their respective properties ans processing according to the specific logic (validation, content editing, etc). a sample procedure might look like:

Private Sub cmdDelete1_Click()
[tab]Call basProcess(txtbox1, txtBox2)
End Sub

with the function:

Private sub basProcess(Text1 as Control, Text2 as Control)

[tab]'validation and processing here, referencing the CONTROLS properties

End Sub

MichaelRed


 
The order in which I would the control process is as follows:

Code:
Private Sub QTY-SHIP-1_AfterUpdate
---->Public Function calcmatlineB Lineno:=1
     'Validates Qty in field to see if it has changed
     'If more has been added it detracts it from Inv.
     'If less has been taken then it adds it to Inv.
     'Calculates Amount in field with unit costs
     'If they decide to Zero out the column I prompt them to delete the line.
     'if yes  
---------->I want to call the command button "delete" & Lineno & "_click" event
           'Could not get this to work...Since I have 10 of these buttons I want to call the approp. 
           "line"'s delete method

So instead of the above I did the following:

Code:
Private Sub QTY-SHIP-1_AfterUpdate
---->Call Public Function calcmatlineB Lineno:=1
     'Validates Qty in field to see if it has changed
     'If more has been added it detracts it from Inv.
     'If less has been taken then it adds it to Inv.
     'Calculates Amount in field with unit costs
     'If they decide to Zero out the column I prompt them to delete the line.
     'if yes  
--------->Call Private Function DeleteLine (Lineno)
          'Updates inventory qty and clears controls on this "line"
----->flow returns to Public Function calcmatlineB Lineno:=1
      'Where it finishes updating unit price, unit total price, Sub-Total, Tax, and total amount.

Does that give everyone a clearer idea as to what I am trying to accomplish?

Ascent
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top