GoToRecord for a subform

  • Thread starter Thread starter Curiousmark
  • Start date Start date
C

Curiousmark

I use a subform to display a list in continous format. When the main form
("frmEncoutner") opens, I want the subform ("subfrmCaseHistory") to display
the last 11 records in the list (it is sorted in chronological order with the
most recent at the bottom), so I use the following commands in the subform
"Form_Open" event:

DoCmd.GoToRecord , , acLast
DoCmd.GoToRecord , , acPrevious, 11

When the user adds data using the main form and enters it, I want the
subform to update with the newest data. I use the requery command in an
application module:

Forms!frmEncounter![Case History].Requery

This works fine, but I can't get the subform to display the last 11 entries.
I've tried using the GoToRecord commands in the subform's DataChange event,
but that doesn't work. I've tried using it in the application module but
can't figure out how to refer to the subform.

For example, if I try:

DoCmd.GoToRecord acDataForm, "Forms!frmEncounter!subfrmCaseHistory",
acLast
DoCmd.GoToRecord acDataForm, "Forms!frmEncounter!subfrmCaseHistory",
acPrevious, 11

No matter what syntax I try, I get the error:

The object "Forms!frmEncounter!subfrmCaseHistory" isn't open.

I've tried every way I can think of to refer to the subform, but get the
same error that the subform isn't open.

Any suggestions?
 
Create a new public sub on the subform something like this:

Public Sub DisplayLast11
DoCmd.GoToRecord , , acLast
DoCmd.GoToRecord , , acPrevious, 11
End Sub


Back on the main form:
With Forms!frmEncounter![Case History]
.Requery
.DisplayLast11
End With


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 
Thanks for your rapid response. I tried it but when it tries to execute the
..DisplayLast11 command, it gives me the error:

"Object doesn't support this property"

What am I missing?

Thanks.

Jeanette Cunningham said:
Create a new public sub on the subform something like this:

Public Sub DisplayLast11
DoCmd.GoToRecord , , acLast
DoCmd.GoToRecord , , acPrevious, 11
End Sub


Back on the main form:
With Forms!frmEncounter![Case History]
.Requery
.DisplayLast11
End With


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia

Curiousmark said:
I use a subform to display a list in continous format. When the main form
("frmEncoutner") opens, I want the subform ("subfrmCaseHistory") to
display
the last 11 records in the list (it is sorted in chronological order with
the
most recent at the bottom), so I use the following commands in the subform
"Form_Open" event:

DoCmd.GoToRecord , , acLast
DoCmd.GoToRecord , , acPrevious, 11

When the user adds data using the main form and enters it, I want the
subform to update with the newest data. I use the requery command in an
application module:

Forms!frmEncounter![Case History].Requery

This works fine, but I can't get the subform to display the last 11
entries.
I've tried using the GoToRecord commands in the subform's DataChange
event,
but that doesn't work. I've tried using it in the application module but
can't figure out how to refer to the subform.

For example, if I try:

DoCmd.GoToRecord acDataForm,
"Forms!frmEncounter!subfrmCaseHistory",
acLast
DoCmd.GoToRecord acDataForm,
"Forms!frmEncounter!subfrmCaseHistory",
acPrevious, 11

No matter what syntax I try, I get the error:

The object "Forms!frmEncounter!subfrmCaseHistory" isn't open.

I've tried every way I can think of to refer to the subform, but get the
same error that the subform isn't open.

Any suggestions?


.
 
There is something weird about the form references.
Assuming that frmEncounter is the name of the main form, then use

With Me.NameOfSubformControl
.Requery
.Form.DisplayLast11
End With

Note: replace NameOfSubformControl with the name of your subform control.
The subform will be *inside* a subform contorl.
The subform control will be on the main form and it may or may not have the
same name as the subform inside it.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia


Curiousmark said:
Thanks for your rapid response. I tried it but when it tries to execute
the
.DisplayLast11 command, it gives me the error:

"Object doesn't support this property"

What am I missing?

Thanks.

Jeanette Cunningham said:
Create a new public sub on the subform something like this:

Public Sub DisplayLast11
DoCmd.GoToRecord , , acLast
DoCmd.GoToRecord , , acPrevious, 11
End Sub


Back on the main form:
With Forms!frmEncounter![Case History]
.Requery
.DisplayLast11
End With


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia

Curiousmark said:
I use a subform to display a list in continous format. When the main
form
("frmEncoutner") opens, I want the subform ("subfrmCaseHistory") to
display
the last 11 records in the list (it is sorted in chronological order
with
the
most recent at the bottom), so I use the following commands in the
subform
"Form_Open" event:

DoCmd.GoToRecord , , acLast
DoCmd.GoToRecord , , acPrevious, 11

When the user adds data using the main form and enters it, I want the
subform to update with the newest data. I use the requery command in an
application module:

Forms!frmEncounter![Case History].Requery

This works fine, but I can't get the subform to display the last 11
entries.
I've tried using the GoToRecord commands in the subform's DataChange
event,
but that doesn't work. I've tried using it in the application module
but
can't figure out how to refer to the subform.

For example, if I try:

DoCmd.GoToRecord acDataForm,
"Forms!frmEncounter!subfrmCaseHistory",
acLast
DoCmd.GoToRecord acDataForm,
"Forms!frmEncounter!subfrmCaseHistory",
acPrevious, 11

No matter what syntax I try, I get the error:

The object "Forms!frmEncounter!subfrmCaseHistory" isn't open.

I've tried every way I can think of to refer to the subform, but get
the
same error that the subform isn't open.

Any suggestions?


.
 
Thanks! Adding "Form" before .DisplayLast11 seems to have done it.

Jeanette Cunningham said:
There is something weird about the form references.
Assuming that frmEncounter is the name of the main form, then use

With Me.NameOfSubformControl
.Requery
.Form.DisplayLast11
End With

Note: replace NameOfSubformControl with the name of your subform control.
The subform will be *inside* a subform contorl.
The subform control will be on the main form and it may or may not have the
same name as the subform inside it.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia


Curiousmark said:
Thanks for your rapid response. I tried it but when it tries to execute
the
.DisplayLast11 command, it gives me the error:

"Object doesn't support this property"

What am I missing?

Thanks.

Jeanette Cunningham said:
Create a new public sub on the subform something like this:

Public Sub DisplayLast11
DoCmd.GoToRecord , , acLast
DoCmd.GoToRecord , , acPrevious, 11
End Sub


Back on the main form:
With Forms!frmEncounter![Case History]
.Requery
.DisplayLast11
End With


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia

I use a subform to display a list in continous format. When the main
form
("frmEncoutner") opens, I want the subform ("subfrmCaseHistory") to
display
the last 11 records in the list (it is sorted in chronological order
with
the
most recent at the bottom), so I use the following commands in the
subform
"Form_Open" event:

DoCmd.GoToRecord , , acLast
DoCmd.GoToRecord , , acPrevious, 11

When the user adds data using the main form and enters it, I want the
subform to update with the newest data. I use the requery command in an
application module:

Forms!frmEncounter![Case History].Requery

This works fine, but I can't get the subform to display the last 11
entries.
I've tried using the GoToRecord commands in the subform's DataChange
event,
but that doesn't work. I've tried using it in the application module
but
can't figure out how to refer to the subform.

For example, if I try:

DoCmd.GoToRecord acDataForm,
"Forms!frmEncounter!subfrmCaseHistory",
acLast
DoCmd.GoToRecord acDataForm,
"Forms!frmEncounter!subfrmCaseHistory",
acPrevious, 11

No matter what syntax I try, I get the error:

The object "Forms!frmEncounter!subfrmCaseHistory" isn't open.

I've tried every way I can think of to refer to the subform, but get
the
same error that the subform isn't open.

Any suggestions?





.


.
 
Back
Top