In the function I was trying to get the control name to get the value to
search on. But if you got it to work, its good.
BTW, instead of using a "GoTo" (> GoTo Exit_Drilldown), just use
"Exit Function".
And in case that there are spaces in the field name, you should add
brackets in strWhere:
strWhereCond = "[" & pstrFieldName & "]" & "=" & pFieldValue
Just my 2 cents worth.....
Glad its working
HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)
oldblindpew wrote:
> Thanks for replying, Steve.
>
> I had already discovered the problem with testing a long integer variable
> for Null. Like much of Access, it doesn't make a lot of sense to me; I'm
> just happy if it works. As I see it, I have a table with a long integer
> foreign key field that starts out empty, so assume it must be Null. I want
> to pass its value to a function so I define the argument variable as same
> type. Once in the function, I test for Null, and get an error because the
> type isn't Variant. Who decided a long integer field cannot be Null?
>
> In your solution, it looks like the name of the active control is passed to
> the function for use as the name of the field to search in the detail form's
> recordset. I wouldn't expect these names to be identical. Many people use
> the same field name for a primary key in one table and the foreign key in
> another, in which case maybe you could pass the Control Source of the Active
> Control?
>
> In my case the field names are not identical. My arguments are 1) the name
> of the form to open, 2) the value of the active control (the value to be
> searched for), and 3) the name of the field to be searched. The Dbl-Click
> event now looks like this:
>
> =Drilldown("formInsPolGL",[Screen].[ActiveControl],"[PolicyID]")
>
> and the code like this:
>
> Function Drilldown(strFormName As String, FieldValue As Variant,
> strFieldName As String)
> ' This function opens a detail form based on a field value in the main form.
> On Error GoTo Err_Drilldown
> Dim strWhereCond As String
> If IsNull(FieldValue) Then
> GoTo Exit_Drilldown
> End If
> strWhereCond = strFieldName & "=" & FieldValue
> DoCmd.OpenForm strFormName, , , strWhereCond
> Exit_Drilldown:
> On Error Resume Next
> Exit Function
> Err_Drilldown:
> MsgBox "Error #: " & Err & Chr(13) & Err.Description, _
> Buttons:=vbCritical, title:="Contract Admin Database"
> Resume Exit_Drilldown
> Resume
>
> End Function
>
> --Pew
>
> "Steve Sanford" wrote:
>
>> Because you have defined FieldValue as a type long, it cannot be null. Well,
>> it can, but it will throw an error.
>>
>> Try this:
>> in the double click event of a control:
>>
>> =Drilldown("formInsPolGL",[ActiveControl].[Name],[ActiveControl])
>>
>>
>> The function:
>> '----------beg code-----------------
>> Function Drilldown(pstrFormName As String, pstrFieldName As String,
>> pFieldValue As Variant)
>>
>> ' This function opens a detail form based on a field value in the main form.
>> Dim strWhereCond As String
>>
>> 'check for text or null
>> If IsNull(pFieldValue) Or Not IsNumeric(pFieldValue) Then
>> Exit Function
>> End If
>>
>> strWhereCond = "[" & pstrFieldName & "]" & "=" & pFieldValue
>> DoCmd.OpenForm pstrFormName, , , strWhereCond
>>
>> Exit_Drilldown:
>> On Error Resume Next
>> Exit Function
>> End Function
>> '----------end code-----------------
>>
>> Note: FieldValue ("FieldValue") is now a variant type
>>
>> Note: I prefixed the arguments with "p" to know which variables are
>> arguments and which are defined within the function.
>>
>>
>> HTH
>> --
>> Steve S
>> --------------------------------
>> "Veni, Vidi, Velcro"
>> (I came; I saw; I stuck around.)
>>
>>
>> "oldblindpew" wrote:
>>
>>> I've got it working, like this:
>>>
>>> Dbl Click event property set to:
>>> =Drilldown("formInsPolGL",[GLpolID],"[PolicyID]=" & [Screen].[ActiveControl])
>>>
>>> Coding in Public Functions module (error handling not shown):
>>> Function Drilldown(strFormName As String, FieldValue As Long, strWhereCond
>>> As String)
>>> ' This function opens a detail form based on a field value in the main form.
>>> If IsNull(FieldValue) Then
>>> GoTo Exit_Drilldown
>>> End If
>>> DoCmd.OpenForm strFormName, , , strWhereCond
>>> Exit_Drilldown:
>>> On Error Resume Next
>>> Exit Function
>>> End Function
>>>
>>> --Pew
>>>