subform event procedure

  • Thread starter Thread starter Susan
  • Start date Start date
S

Susan

Hi there:

I have a subform that's a datasheet containing a summary
of a table. I have created an event procedure for when
the user double clicks on a row - a new form is opened
with all of the info from the table based on the Index
field.

When I open the subform on its own, this works perfectly.
When I open the subform as a part of the parent form and
double click on an item, it prompts me for the value of
the Index field.

Can anyone please tell me if I've forgotten something?

Thanks,
Susan
 
If you are referencing another control on the subform, you have to have to
reference it THROUGH the main form when you open it as part of the parent
form. Something like:
Forms!MyParentForm!MySubFormControl.Form!MyControlOnSubform

On my website is a small sample database called "SubformReference" which
explains the problem and solution to a number of issues with subform
referencing.
 
You may have to provide your event procedure so we can see what's up.

My guess is that you have a reference such as:
Forms![NameOfYourForm]![NameOfYourControl]
in the code. When the form is opened as a subform, it is not part of the
Forms collection, so the reference would fail and Access will ask you for
the value. If that's what is happening, just refer to the name of the
control, i.e.:
[NameOfYourControl]
without the rest of the reference.
 
Thanks for your quick reply. I understand what you're
saying but I'm still having problems.

There is no control under Form for Datasheet. Do I just
use the name of my field and it will provide the value
from the currently selected row?

I'm now able to get the new form to pop up without a
prompt... but it's always filled in with data from the
first field only.

-----Original Message-----
You may have to provide your event procedure so we can see what's up.

My guess is that you have a reference such as:
Forms![NameOfYourForm]![NameOfYourControl]
in the code. When the form is opened as a subform, it is not part of the
Forms collection, so the reference would fail and Access will ask you for
the value. If that's what is happening, just refer to the name of the
control, i.e.:
[NameOfYourControl]
without the rest of the reference.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

I have a subform that's a datasheet containing a summary
of a table. I have created an event procedure for when
the user double clicks on a row - a new form is opened
with all of the info from the table based on the Index
field.

When I open the subform on its own, this works perfectly.
When I open the subform as a part of the parent form and
double click on an item, it prompts me for the value of
the Index field.

Can anyone please tell me if I've forgotten something?

Thanks,
Susan


.
 
In case you are still thinking about my problem, here is
my procedure - it's pretty simple! I added a MsgBox that
sucessfully posts the proper value (QUERY_TI_Index)...
then I'm prompted to enter it again before the new form is
opened up. I've tried including all combinations of the
whole form name, just the control name, square brackets,
no brackets...

I'll continue playing with it & post one last message if
I've solved the problem.

Thanks!
Susan


------------------------------------
Private Sub TestName_DblClick(Cancel As Integer)
On Error GoTo Err_TestName_DblClick

Dim stDocName As String
Dim stLinkCriteria As String

MsgBox (QUERY_TI_Index)

stDocName = "JustTestInfo"
stLinkCriteria = "TI_Index = [QUERY_TI_Index]"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_TestName_DblClick:
Exit Sub

Err_TestName_DblClick:
MsgBox Err.Description
Resume Exit_TestName_DblClick

End Sub

--------------------------------

-----Original Message-----
You may have to provide your event procedure so we can see what's up.

My guess is that you have a reference such as:
Forms![NameOfYourForm]![NameOfYourControl]
in the code. When the form is opened as a subform, it is not part of the
Forms collection, so the reference would fail and Access will ask you for
the value. If that's what is happening, just refer to the name of the
control, i.e.:
[NameOfYourControl]
without the rest of the reference.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

I have a subform that's a datasheet containing a summary
of a table. I have created an event procedure for when
the user double clicks on a row - a new form is opened
with all of the info from the table based on the Index
field.

When I open the subform on its own, this works perfectly.
When I open the subform as a part of the parent form and
double click on an item, it prompts me for the value of
the Index field.

Can anyone please tell me if I've forgotten something?

Thanks,
Susan


.
 
Hi Susan. Yes, that's the right idea.

Try concatenating the value of your QUERY_TI_Index field into the criteria
string.

If TI_Index is a Number type field, that would be:
stLinkCriteria = "TI_Index = " & [QUERY_TI_Index]
If it is a Text type field, it needs extra quotes:
stLinkCriteria = "TI_Index = """ & [QUERY_TI_Index] & """"

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

In case you are still thinking about my problem, here is
my procedure - it's pretty simple! I added a MsgBox that
sucessfully posts the proper value (QUERY_TI_Index)...
then I'm prompted to enter it again before the new form is
opened up. I've tried including all combinations of the
whole form name, just the control name, square brackets,
no brackets...

I'll continue playing with it & post one last message if
I've solved the problem.

Thanks!
Susan


------------------------------------
Private Sub TestName_DblClick(Cancel As Integer)
On Error GoTo Err_TestName_DblClick

Dim stDocName As String
Dim stLinkCriteria As String

MsgBox (QUERY_TI_Index)

stDocName = "JustTestInfo"
stLinkCriteria = "TI_Index = [QUERY_TI_Index]"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_TestName_DblClick:
Exit Sub

Err_TestName_DblClick:
MsgBox Err.Description
Resume Exit_TestName_DblClick

End Sub

--------------------------------

-----Original Message-----
You may have to provide your event procedure so we can see what's up.

My guess is that you have a reference such as:
Forms![NameOfYourForm]![NameOfYourControl]
in the code. When the form is opened as a subform, it is not part of the
Forms collection, so the reference would fail and Access will ask you for
the value. If that's what is happening, just refer to the name of the
control, i.e.:
[NameOfYourControl]
without the rest of the reference.

I have a subform that's a datasheet containing a summary
of a table. I have created an event procedure for when
the user double clicks on a row - a new form is opened
with all of the info from the table based on the Index
field.

When I open the subform on its own, this works perfectly.
When I open the subform as a part of the parent form and
double click on an item, it prompts me for the value of
the Index field.

Can anyone please tell me if I've forgotten something?

Thanks,
Susan
 
Thank you so much, Allen - I can't believe my silly
mistake!
-----Original Message-----
Hi Susan. Yes, that's the right idea.

Try concatenating the value of your QUERY_TI_Index field into the criteria
string.

If TI_Index is a Number type field, that would be:
stLinkCriteria = "TI_Index = " & [QUERY_TI_Index]
If it is a Text type field, it needs extra quotes:
stLinkCriteria = "TI_Index = """ & [QUERY_TI_Index] & """"

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

In case you are still thinking about my problem, here is
my procedure - it's pretty simple! I added a MsgBox that
sucessfully posts the proper value (QUERY_TI_Index)...
then I'm prompted to enter it again before the new form is
opened up. I've tried including all combinations of the
whole form name, just the control name, square brackets,
no brackets...

I'll continue playing with it & post one last message if
I've solved the problem.

Thanks!
Susan


------------------------------------
Private Sub TestName_DblClick(Cancel As Integer)
On Error GoTo Err_TestName_DblClick

Dim stDocName As String
Dim stLinkCriteria As String

MsgBox (QUERY_TI_Index)

stDocName = "JustTestInfo"
stLinkCriteria = "TI_Index = [QUERY_TI_Index]"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_TestName_DblClick:
Exit Sub

Err_TestName_DblClick:
MsgBox Err.Description
Resume Exit_TestName_DblClick

End Sub

--------------------------------

-----Original Message-----
You may have to provide your event procedure so we can see what's up.

My guess is that you have a reference such as:
Forms![NameOfYourForm]![NameOfYourControl]
in the code. When the form is opened as a subform, it
is
not part of the
Forms collection, so the reference would fail and
Access
will ask you for
the value. If that's what is happening, just refer to
the
name of the
control, i.e.:
[NameOfYourControl]
without the rest of the reference.


I have a subform that's a datasheet containing a summary
of a table. I have created an event procedure for when
the user double clicks on a row - a new form is opened
with all of the info from the table based on the Index
field.

When I open the subform on its own, this works perfectly.
When I open the subform as a part of the parent form and
double click on an item, it prompts me for the value of
the Index field.

Can anyone please tell me if I've forgotten something?

Thanks,
Susan


.
 
Back
Top