Private Sub

  • Thread starter Thread starter Robert
  • Start date Start date
R

Robert

Access 2000...

I have a private sub with a simple calculation (it works).
However, when use a call procedure, it fails. Any advise?

Private Function Function1(A)
Function1 = A + 1
End Function

There is a text box that I have the ControlSource="Amount
saved " & Function1(2)

Then, I have a command button where the OnClick event is
the following:

Private Sub cmdButton2_Click()
Call Function1(3)
End Sub

The call procedure does not update the text box.

Thanks in advance for any assistance.
 
Robert said:
Access 2000...

I have a private sub with a simple calculation (it works).
However, when use a call procedure, it fails. Any advise?

Private Function Function1(A)
Function1 = A + 1
End Function

There is a text box that I have the ControlSource="Amount
saved " & Function1(2)

Then, I have a command button where the OnClick event is
the following:

Private Sub cmdButton2_Click()
Call Function1(3)
End Sub

The call procedure does not update the text box.

I fail to see why it would. A Function would be used in an assignment statement.
Just calling it without setting something equal to what is returned will do nothing.
 
Hi



A user defined function is something that could be use a thousand times into
a book. If you Call it somewhere and, at that place, you don't store the
resold it won't know what to do. The best is to use it directly in the cell.
Try this modification:



Public Function Function1(A)

Function1 = "Amount Saved " & CStr(A + 1)

End Function
 
Robert,

Private Sub cmdButton2_Click()
me.txtbox14.Value = Function1(3) ' substitute the actual name of the
textbox here
End Sub
 
Back
Top