By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,660 Members | 1,215 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,660 IT Pros & Developers. It's quick & easy.

Move to Last record on a subform

P: n/a
I have built a database with a <Mainform> and a <Subform>. My problem is
twofold.

1. My subform is set as a continuos form with AllowAddiotions set to NO (ie.
a list of Issues to the client on the mainform)
2. To add new issues, a button is used and a pop-up form is used to add an
issue with more detail than what's available on the subform.
3. On accepting the new Issue from the pop-up the pop-up closes and you are
returned to the subform, and the new line is added, but the active record is
the first record and not the new one.

Problem: I have tried docmd.runcommand accmdrecordsgotolast and
docmd.GoToRecord acDataForm ,,acLast with no avail. I am getting errors
that the cmd is not available. I preface that with a requery and moving
control to the subform, either to the form itself or field on the subform,
still no luck. If I use the GoToRecord and specify the
Foms!mainform!subform as the object, I get an error that tells me the form
is not open (but it is).

Is there an easy way to move to the last record, I'm not certain what I may
be doing wrong.

The second problem I am running into is I need an event to occur when I move
out of a record (similar to onExit) and not into record that OnCurrent
provides. The afterupdate is of no use to me since changes may not occur.

Any help would be appreciated.

Thanks
Nov 12 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
This code will requery the record in the subform, and move focus to the last
record:

Expand|Select|Wrap|Line Numbers
  1. Dim frm As Form
  2. Set frm = Forms![YourMainForm]![YourSubformControl].Form
  3. frm.Requery
  4. With frm.RecordsetClone
  5. If .RecordCount > 0 Then
  6. .MoveLast
  7. frm.Bookmark = .Bookmark
  8. End If
  9. End With
  10. Set frm = Nothing
There is no event of exiting a record. The solution might depend on what you
need to do, but one approach is to declare a form-level variable to store
the primary key value, and then read it in the form's Current or Unload
event (the 2 occasions when you "leave" a record).

In the General Declarations of the form's module (at the top, with the
Option statements):
Dim mvarID As Variant

In the Current event procedure of the form:
Expand|Select|Wrap|Line Numbers
  1. Dim strMsg As String
  2. If Not IsEmpty(varID) Then
  3. If IsNull(varID) Then
  4. strMsg = "You just left the new record"
  5. Else
  6. strMsg = "You just left record ID " & mvarID
  7. End If
  8. mvarID = Me.[YourPrimaryKeyField]
  9. MsgBox strMsg
  10. End If
Do something similar in the form's Unload event.
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"sixsoccer" <si*******@yahoo.com> wrote in message
news:Vu******************@news04.bloor.is.net.cabl e.rogers.com...
I have built a database with a <Mainform> and a <Subform>. My problem is
twofold.

1. My subform is set as a continuos form with AllowAddiotions set to NO (ie. a list of Issues to the client on the mainform)
2. To add new issues, a button is used and a pop-up form is used to add an
issue with more detail than what's available on the subform.
3. On accepting the new Issue from the pop-up the pop-up closes and you are returned to the subform, and the new line is added, but the active record is the first record and not the new one.

Problem: I have tried docmd.runcommand accmdrecordsgotolast and
docmd.GoToRecord acDataForm ,,acLast with no avail. I am getting errors
that the cmd is not available. I preface that with a requery and moving
control to the subform, either to the form itself or field on the subform,
still no luck. If I use the GoToRecord and specify the
Foms!mainform!subform as the object, I get an error that tells me the form
is not open (but it is).

Is there an easy way to move to the last record, I'm not certain what I may be doing wrong.

The second problem I am running into is I need an event to occur when I move out of a record (similar to onExit) and not into record that OnCurrent
provides. The afterupdate is of no use to me since changes may not occur.

Any help would be appreciated.

Thanks

Nov 12 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.