Passing a reference of a object on a form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have this code on one form

Private Sub Owner_DblClick(Cancel As Integer
On Error GoTo Err_Owner_DblClic
Dim lngOwner As Lon
If IsNull(Me![Owner]) The
Me![Owner].Text = "
Els
lngOwner = Me![Owner
Me![Owner] = Nul
End I
DoCmd.OpenForm "Who Entry
Me![Owner].Requer
If lngOwner <> 0 Then Me![Owner] = lngOwne
Exit_Owner_DblClick
Exit Su
Err_Owner_DblClick
MsgBox Err.Descriptio
Resume Exit_Owner_DblClic
End Su

But I would like to modify it and place it in a class module so I can use it on several forms. How do I pass a reference of the combobox "Owner" to the function in the module so that I can replace all the me![owner]?
 
Hi,
The signature would be:
Public Sub YourFunction(ctl As ComboBox)
'then just substitute ctl where ever you used Me![Owner]
End Sub

HTH
Dan Artuso

AdmSteck said:
I have this code on one form:

Private Sub Owner_DblClick(Cancel As Integer)
On Error GoTo Err_Owner_DblClick
Dim lngOwner As Long
If IsNull(Me![Owner]) Then
Me![Owner].Text = ""
Else
lngOwner = Me![Owner]
Me![Owner] = Null
End If
DoCmd.OpenForm "Who Entry"
Me![Owner].Requery
If lngOwner <> 0 Then Me![Owner] = lngOwner
Exit_Owner_DblClick:
Exit Sub
Err_Owner_DblClick:
MsgBox Err.Description
Resume Exit_Owner_DblClick
End Sub


But I would like to modify it and place it in a class module so I can use it on several forms. How do I pass a reference of
the combobox "Owner" to the function in the module so that I can replace all the me![owner]?
 
This is untested.

Me!Owner refers to the underlying recordset field and not the combobox
itself so adjustments may be necessary, but hopefully this will get you
started.

Private Sub Owner_DblClick(Cancel As Integer)
Call CheckOwner(Me.cboOwner)
End Sub

Public Sub CheckOwner(cbo as ComboBox)
On Error GoTo ErrHandler
Dim lngOwner As Long
If IsNull(cbo) Then
cbo.Text = ""
Else
lngOwner = cbo
cbo = Null
End If
DoCmd.OpenForm "Who Entry"
cbo.Requery
If lngOwner <> 0 Then cbo = lngOwner
ExitHere:
Exit Sub
ErrHandler:
MsgBox Err.Description
Resume ExitHere
End Sub

--
George Nicholson

Remove 'Junk' from return address.


AdmSteck said:
I have this code on one form:

Private Sub Owner_DblClick(Cancel As Integer)
On Error GoTo Err_Owner_DblClick
Dim lngOwner As Long
If IsNull(Me![Owner]) Then
Me![Owner].Text = ""
Else
lngOwner = Me![Owner]
Me![Owner] = Null
End If
DoCmd.OpenForm "Who Entry"
Me![Owner].Requery
If lngOwner <> 0 Then Me![Owner] = lngOwner
Exit_Owner_DblClick:
Exit Sub
Err_Owner_DblClick:
MsgBox Err.Description
Resume Exit_Owner_DblClick
End Sub


But I would like to modify it and place it in a class module so I can use
it on several forms. How do I pass a reference of the combobox "Owner" to
the function in the module so that I can replace all the me![owner]?
 
Back
Top