[AccessD] A2K: Pass Field Name to function. Solved

Darren DICK d.dick at uws.edu.au
Thu Apr 10 00:01:50 CDT 2003


Hi Chris and Michael
Thanks to you both for the quick response
I went with Chris' method (It was the first one I
tried) :-)
Many many thanks guys

Darren

Final code for anyone who wants it is...

--------------------------------------------------
--------------------------------------------------
------
Function fComboDoubleClick(stFormToOpen As String,
stFieldToFilter As String, stCallingForm As
String)

'Function to open a dataset/table via a popup form
where that dataset/table feeds the rowsource of
the combo
'that has been double clicked - and to be take to
the relevant record in the popup form

On Error GoTo Err_Function

    If IsNull(Forms(stCallingForm).ActiveControl)
Or Forms(stCallingForm).ActiveControl = "" Then
        DoCmd.OpenForm stFormToOpen
    Else
        DoCmd.OpenForm stFormToOpen

Forms(stFormToOpen).RecordsetClone.FindFirst
stFieldToFilter & " = " &
Forms(stCallingForm).ActiveControl
        Forms(stFormToOpen).Bookmark =
Forms(stFormToOpen).RecordsetClone.Bookmark
   End If

Exit_Function:
Exit Function

Err_Function:
MsgBox Err.Number & " " & Err.Description,
vbCritical, "OABIS"

Resume Exit_Function

End Function
--------------------------------------------------
--------------------------------------------------
------
Example of how to call it
Private Sub cmbBroadcastTypeID_DblClick(Cancel As
Integer)
Call fComboDoubleClick("frmBroadcastTypes",
"BroadcastTypeID", Me.Form.Name)
'This of course assumes you have a form called
frmBroadcastTypes and its bound
'dataset has a fieldname called BroadcastTypeID
End Sub


----- Original Message -----
From: "Chris Mackin" <chris at denverdb.com>
To: <accessd at databaseadvisors.com>
Sent: Thursday, April 10, 2003 2:14 PM
Subject: RE: [AccessD] A2K: Pass Field Name to
function


> Use this instead:
>
> Forms(stDocName).RecordsetClone.FindFirst
stFieldToFilter & " = " &
> Me.ActiveControl
>
> of course you will want to make sure that you
watch out for Text or Date
> data type in thos fields, which require the
'Value' or #Value# instead of
> the above which will work for a numeric Field.
>
> Chris Mackin
> Denver Database Consulting, LLC
> www.denverdb.com
>
>
>
> -----Original Message-----
> From: accessd-bounces at databaseadvisors.com
> [mailto:accessd-bounces at databaseadvisors.com]On
Behalf Of Darren DICK
> Sent: Wednesday, April 09, 2003 10:09 PM
> To: accessd at databaseadvisors.com
> Subject: [AccessD] A2K: Pass Field Name to
function
>
>
> Hello all
> The commented code below works fine.
> That is if I type the FieldName in directly
> What I want to do is pass in the FieldName from
> passes parameters
> I just can't get the syntax right.
>
> Any help or suggestions would be most
appreciated
>
> Many thanks
>
> Darren
>
>
__________________________________________________
> _________________________
> Function fComboDoubleClick(stFormToOpen As
String,
> stFieldToFilter As String)
>
> <code Snip>
>         DoCmd.OpenForm stFormToOpen ' This line
> works
>         'The line below works when
BroadcastTypeID
> is typed in Manually
>
'Forms(stDocName).RecordsetClone.FindFirst
> "[BroadcastTypeID ]=" & Me.ActiveControl
>          'The line below fails whan I try and
pass
> the field name as a parameter
>
Forms(stDocName).RecordsetClone.FindFirst
> " & stFieldToFilter  & = " & Me.ActiveControl
> <code Snip>
>
__________________________________________________
> _________________________
>
> _______________________________________________
> AccessD mailing list
> AccessD at databaseadvisors.com
>
http://databaseadvisors.com/mailman/listinfo/acces
sd
> Website: http://www.databaseadvisors.com
>
>
>
> _______________________________________________
> AccessD mailing list
> AccessD at databaseadvisors.com
>
http://databaseadvisors.com/mailman/listinfo/acces
sd
> Website: http://www.databaseadvisors.com



More information about the AccessD mailing list