Changing Source Object of subform

J

jhanby1

So I am having problems. I have set up a particular subform
(fsubCaseDetails) to change its source object when the user clicks the
cmdBackToSearch command button:

Private Sub cmdBackToSearch_Click()
'Return to the Case Search form based on user response.

Dim strResponse As String

strResponse = Msgbox("Are you sure you want to close the Case
Details and return to the Case Search?", vbOKCancel, "MAPS")
If strResponse = vbOK Then
Forms!frmMainPage2.Refresh
Forms!frmMainPage2!fsubCaseDetails.SourceObject =
fsubCaseSearch
Else
Cancel = True
End If
End Sub

When I click the Ok button in the message box, the subform goes blank.
So it seems like it is changing the subform's source object, but the
Case Search subform is not properly displayed. I'm not sure if its a
refresh problem or what...any ideas?????
 
J

John Vinson

When I click the Ok button in the message box, the subform goes blank.
So it seems like it is changing the subform's source object, but the
Case Search subform is not properly displayed. I'm not sure if its a
refresh problem or what...any ideas?????

The SourceObject property should be a String, the name of the form you
want displayed. I think you need quotes around it:

If strResponse = vbOK Then
Forms!frmMainPage2.Refresh
Forms!frmMainPage2!fsubCaseDetails.SourceObject =
"fsubCaseSearch"

(without the linewrap of course).

It may be setting the SourceObject to the value of the (undeclared)
variable fsubCaseSearch, which will be NULL; if (as recommended) you
include Option Explicit at the very top of your code, it would have
given you an error message rather than silently failing.

John W. Vinson[MVP]
 

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