Calling a Function

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have an Access 97. On one form, the user can scan or enter a number into a
control. The KeyDown event (with keycode 13) is used to check (through an IF
statement) whether a function has returned True or False. The function
itself does a lot of things like check for a valid user, that a number was
actually entered and calls 2 other functions one of which retrieves matched
data from a Visual Fox Pro data source and inserts it into the Access table.

My (perhaps dumb) question is this:

Can an IF statement be a call for a function? I have looked thoughout the
code looking for a call statement but there isn't one. Here is the code that
I believe triggers the function:


Private Sub Access_No_KeyDown(KeyCode As Integer, Shift As Integer)
'Description
'This code will insert the sample from VFP database

With Me
If KeyCode = 13 Then 'Enter
.cmdClose.SetFocus
If XYZFunction = True Then
![ControlXYZ] = ""
.ControlXYZ.SetFocus
End If
End If
End With
End Sub
 
LeAnn said:
I have an Access 97. On one form, the user can scan or enter a
number into a control. The KeyDown event (with keycode 13) is used
to check (through an IF statement) whether a function has returned
True or False. The function itself does a lot of things like check
for a valid user, that a number was actually entered and calls 2
other functions one of which retrieves matched data from a Visual Fox
Pro data source and inserts it into the Access table.

My (perhaps dumb) question is this:

Can an IF statement be a call for a function? I have looked
thoughout the code looking for a call statement but there isn't one.
Here is the code that I believe triggers the function:


Private Sub Access_No_KeyDown(KeyCode As Integer, Shift As Integer)
'Description
'This code will insert the sample from VFP database

With Me
If KeyCode = 13 Then 'Enter
.cmdClose.SetFocus
If XYZFunction = True Then
![ControlXYZ] = ""
.ControlXYZ.SetFocus
End If
End If
End With
End Sub

Since the big difference between functions and subs is that a function
returns a value, a function name (with arguments if needed) can be used
in VBA code anywhere a value or expression can be used. You don't need
a Call statement.

In the code you posted, the line
If XYZFunction = True Then

calls function XYZFunction (with no arguments) and compares the value it
returns to the constant True.
 
Back
Top