Parent.RecordSource in a popup

  • Thread starter Thread starter VWP1
  • Start date Start date
V

VWP1

On another post (below), I read that a textbox can be created to access the
record source of the form on which it resides.

Can I create a popup form (lets call it SQL POPUP) (which will activate from
clicking a button on the form having the button MAINFORM) in which SQL POPUP
has a textbox containing the recordsource of the MAINFORM?

1/17/2010 12:25 PM PST
Author: Presto

---snippet---
Title of Post: Show record source in a text box

I need to weed out a very overcrowded database. I need to remove ...
---end snippet---

Marshall Barton wrote:

Me is not valid in a control expression. The main form can
refer to its own record source using =Form.RecordSource.
The subform can refer to the main form's record source using
=Parent.RecordSource
 
Just use the appropriate form object instead of Form or
Parent.

I think this will do what you want:
=Forms!MAINFORM.RecordSource
 
VWP1 said:
On another post (below), I read that a textbox can be created to access
the
record source of the form on which it resides.

Can I create a popup form (lets call it SQL POPUP) (which will activate
from
clicking a button on the form having the button MAINFORM) in which SQL
POPUP
has a textbox containing the recordsource of the MAINFORM?

If you just want to display the recordsource, this ControlSource expression
would work for a calculated text box:

=Forms!MAINFORM.RecordSource

Note that such an expression will give a #Name error if MAINFORM is not
open.

If your intention is to edit the recordsource, you can't use a calculated
control. Then you'd have to use code to set the value of the text box and,
if desired, update the recordsource of the form after the user has edited
it.
 
Works great.

Now, in order to view the Select Statement for each "regular" form, I would
need a corresponding popup form. Any way to use the same popup form for all
the forms?
 
VWP1 said:
Works great.

Now, in order to view the Select Statement for each "regular" form, I
would
need a corresponding popup form. Any way to use the same popup form for
all
the forms?

I haven't tried it, but it seems to me that you could pass the name of the
desired form via OpenArgs when you open the popup form, like this:

DoCmd.OpenForm "frmSQLPopup", _
OpenArgs:=Me.Name

.... and then have code in the popup form's Open event set the value of an
unbound text box, like this:

'----- start of code -----
Private Sub Form_Open(Cancel As Integer)

Dim strFormToDisplay As String

strFormToDisplay = Me.OpenArgs & vbNullString
If Len(strFormToDisplay) = 0 Then
strFormToDisplay = Screen.ActiveForm.Name
End If

Me.txtShowRecordsource = Forms(strFormToDisplay).RecordSource

End Sub
'----- end of code -----

In this case, you wouldn't be using a calculated text box, but just an
unbound one -- its ControlSource would be blank.
 
Back
Top