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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

a very generic question

Status
Not open for further replies.

sabavno

Programmer
Jul 25, 2002
381
0
0
CA
Hi,

I want to create a function and pass the parameter to it and from it back to another procedure

Can anyone please give the gereneral idea (example).

Thanks.
 
See the Function statement example in the Access help file.
 
Here is an example:

--------
returnExample = Call functionExample(parameterExample)
--------

In function1 you need to set the 'parameter' to what you are looking to pass back.

Hope this helps.
 
Here is an example for you. The first sub calls the function IsRecord. The result is passed back in the IsRecord function. Hope this helps.

Private Sub Event_ID_BeforeUpdate(Cancel As Integer)
Dim CheckExistingRecord As Boolean
'HERE IS THE EXAMPLE
CheckExistingRecord = IsRecord(Me!Event_ID, Me!Contact_ID)
If CheckExistingRecord = True Then
Me.Undo
DoCmd.Close acForm, "Attendance"
Exit Sub
End If
End Sub



Function IsRecord(intEvent_ID As Integer, intContact_ID As Long)
'look thru the recordset to verify if a record exists
On Error GoTo Err_IsRecord
Dim dbs As Database
Dim rst As Recordset
Dim strCriteria As String
Set dbs = CurrentDb
Set rst = CurrentDb.OpenRecordset("Event", dbOpenDynaset)
DoCmd.Hourglass False
With rst
strCriteria = "[Event_ID] = " & intEvent_ID & " And [Contact_ID] = " & intContact_ID
With rst
.MoveFirst
.FindFirst strCriteria
If .NoMatch = True Then
IsRecord = False
Else
MsgBox "A previous record has been found!"
'RETURN THE PARAMETER BACK TO THE CALLING PROCEDURE HERE.
IsRecord = True
End If
.Close
End With
Exit_IsRecord:
DoCmd.Hourglass False
Exit Function
Err_IsRecord:
Resume Exit_IsRecord
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top