I am reposting my question because I just realized that I posted in the wrong forum (previous post is in Microsoft: Access Forms).
I am trying to use dlookup to find the phone number of a person based on there name. I am trying to due this using a global function because I need to due this in more than one form. The problem that I am having is that I can get to run but not the other. Any help in fixing would be appreciated.
Thank You,
rjoshi2
My code
Form Class Module
Private Sub Reference_Person_AfterUpdate()
Dim try As Object
try = ReferencePerson(Me)
end sub
Global Module
Public Function ReferencePerson(ByRef frmRef As Form)
If IsNull(frmRef.ActiveControl) = False Then
frmRef.Phone_Number = DLookup("[Phone Number]", "[tblPscITAcquisitionLog]", "[Reference Person]= Forms![XXXXX]![Reference Person]"
Else
frmRef.Phone_Number = Null
End If
End Function
This code will work for one form or the other if make XXXXX the name of that form (frmDataEntry1 or frmDataEntry2). I am not sure how to pass in the name of the form in. I tried to passing the name in ByRef but it did not work the way I did it.
I am trying to use dlookup to find the phone number of a person based on there name. I am trying to due this using a global function because I need to due this in more than one form. The problem that I am having is that I can get to run but not the other. Any help in fixing would be appreciated.
Thank You,
rjoshi2
My code
Form Class Module
Private Sub Reference_Person_AfterUpdate()
Dim try As Object
try = ReferencePerson(Me)
end sub
Global Module
Public Function ReferencePerson(ByRef frmRef As Form)
If IsNull(frmRef.ActiveControl) = False Then
frmRef.Phone_Number = DLookup("[Phone Number]", "[tblPscITAcquisitionLog]", "[Reference Person]= Forms![XXXXX]![Reference Person]"
Else
frmRef.Phone_Number = Null
End If
End Function
This code will work for one form or the other if make XXXXX the name of that form (frmDataEntry1 or frmDataEntry2). I am not sure how to pass in the name of the form in. I tried to passing the name in ByRef but it did not work the way I did it.