Open Form on Last Record

  • Thread starter Thread starter randar
  • Start date Start date
R

randar

Guest
I have a switchboard that lets you choose between three forms. Each of the three forms contains 1 subform. I have the following code in the Switchboard:

' Open a form in Edit mode.
Case conCmdOpenFormBrowse
DoCmd.OpenForm rs![Argument]
DoCmd.GoToRecord , , acLast

On my first form, this does exactly what I want it to do. It pulls up the last record of the form. If I choose the second or third option from the Switchboard, then the main form opens on the first record and the subform goes to the last record. This happens regardless of which button I choose first after opening the Switchboard. The first button works the way I want it, but the other two do not.

If anyone has any suggestions, please let me know. Thanks!!
 
It sounds like your sub-form is not linked to the parent form. If the sub-form is linked (parent-child relationship) it should sync up correctly.
 
Is there a way to check and see if my forms are linked (have this parent-child relationship)?
 
When you have a subform inserted into a form there is a new border created. If you are viewing the main form in design view and you click on the edge of the border you should then be able to select the property sheet and see a parent field property and a child field property. It may be easier to right click on the edge of the subform and select properties.
 
I checked the properties of the subforms, and there are child and master fields (I am guessing master and parent are equivalent). I am still unable to get the subforms to open to the last record except in the first form.

Here is what I have listed on the form that works the way I want it to:

Source Object: subfrmShiftLog
Link Child Fields: LogPage
Link Master Fields: LogPage
Enabled: Yes

Here is what I have listed on one of the forms that is not working the way that I want it to:

Source Object: subfrmEventLog
Link Child Fileds: LogPage
Link Master Fields: LogPage
Enabled: Yes

The main table (tblShiftLog) has an indexed field called LogPage. All of the other tables (tblShiftTickets and tblEvents in this example) have a field called LogPage which is the same type as the indexed field in the main table.

I am using Access 2003 if that makes any difference. Thank you all for your help. Any ideas would be appreciated.
 
I can only offer an alternative method...

In the switchboard, pass info to the form so that it knows what to do.
Code:
DoCmd.OpenForm "FormName", , , ,, , "EditMode"

In the forms' load event, see if any info was passed in and react...
Code:
If Len(openargs) Then
   Select Case openArgs
      Case "EditMode"
           DoCmd.GoToRecord , , acLast
      Case "SomethingElse"
   End Select
End if

I'm winging it with the code. You'll have to adjust for your needs.

Regards,
Tim
 
The form you want to display the last record, is it a continuous form?

If it is a continuous form is it feasible just to change your sort order so the last record is displayed first?

I am a little confused, but I too can only offer an alternative. Consider using the "on activate" or "on open" events of the forms to determine how they act and what records they open to.
 
Last edited:
yeatmanj said:
I am a little confused, but I too can only offer an alternative. Consider using the "on activate" or "on open" events of the forms to determine how they act and what records they open to.

That worked!!!

I'm pretty excited. I hadn't thought about just inserting the DoCmd.GoToRecord , , acLast into the code to have the main form open up on the last page. That worked perfectly.

Thank you all for your help!
 

Users who are viewing this thread

Back
Top Bottom