How to access controls on calling form from Public Function?

W

WDSnews

My reading and experiments have failed so I set up this experiment which
also failed. I want this Module1 function to return the name of a control
and its value.

Public Function FindAssets( _
lngBarcodeID As Long, _
lngAssetsID As Long, _
frm As Object) As String

'Return the name of a control and its value
FindAssets = [Forms].frm.[cboTitle].Name & ", " & _
[Forms].frm.[cboTitle].Column(1).Value
End Function
---

I created a button to test the function

Private Sub Button42_Click()
MsgBox prompt:=FindAssets(Nz(Me.ID, 0), Nz(Me.Asset_ID, 0), Me)
End Sub

I appreciate your suggestions.
 
T

Tom Wickerath

Hi WDS,

Try something like this:

Private Sub cmdResult_Click()
MsgBox prompt:=FindAssets(Nz(Me.ID, 0), _
Nz(Me.Asset_ID, 0), Me.Name)
End Sub


In Stand-Alone module:

Public Function FindAssets( _
lngBarcodeID As Long, _
lngAssetsID As Long, _
strForm As String) As String

On Error GoTo ProcError

Debug.Print Forms(strForm).[cboTitle].Name
Debug.Print Forms(strForm).[cboTitle].Column(1)

'Return the name of a control and its value
FindAssets = Forms(strForm).[cboTitle].Name & ", " & _
Forms(strForm).[cboTitle].Column(1)


ExitProc:
Exit Function
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in RunUpdates Procedure..."
Resume ExitProc
End Function


Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
__________________________________________
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top