passing a control to a Sub

S

smk23

In the following code, I am trying to pass a control to a sub so that I can
change the default value on that control if needed. Do I need to set the
control in the calling code? I don't get a compile error or runtime error
with the following, but the default is not reset:

Private Sub ReportTemplateIDOR_AfterUpdate()

sReportDefault Me.ReportTemplateIDOR, _
Me.ReportTemplateIDOR.value

End Sub

Private Sub sReportDefault( _
ctReport As Control, _
lngReportTemplateID As Long)
On Error GoTo Error_Handler

Dim strTitle As String
Dim strInput As String
Dim blnResponse As Boolean

strTitle = "Default Report"
strInput = "Do you want to make this the permanent report default? "

blnResponse = MsgBox(strInput, vbYesNo, strTitle)

If blnResponse = True Then
ctReport.DefaultValue = lngReportTemplateID
End If
 
J

Jim Burke in Novi

I think you just need to use ByRef in the sub, e.g.

Private Sub sReportDefault( _
ByRef ctReport As Control, _
lngReportTemplateID As Long)

I think the default is ByVal, which won't work if you want to change the
value.
 
S

smk23

Still not working. When I check the value of ctReport, even with ByRef, I am
seeing the value of the control, not the name of the control.

Sam
 

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