Subform - Accessing last record.

robtyketto

Registered User.
Local time
Today, 21:51
Joined
Nov 22, 2006
Messages
21
Greetings,

I have a main form. Upon filling in a combo box it then displays a subform (based on a query that uses values in the combo box on where clause)

THe subform has the paramater Data Entry = 'No' as I want users to see all existing records and all additions/deletions and edits.

However I want to move to the last record to default, allowing the user to add a record without navigating themselves to the last record.

A popular request, so found code (see below)

Code:
Private Sub cboDeliveryName_AfterUpdate()

  Me.qryStudentsResultsDeliverysubform1.Enabled = True
  Me.qryStudentsResultsDeliverysubform1.Visible = True
  Me.qryStudentsResultsDeliverysubform1.SetFocus
   
    With Me.qryStudentsResultsDeliverysubform1.Form.RecordsetClone
       If Not .BOF Then
            .MoveLast
            MsgBox "In here"
            Me.qryStudentsResultsDeliverysubform1.Form.Bookmark = .Bookmark
      End If
    End With
    
End Sub

When testing the subform is populated with 1 or more rows but the debug message is NEVER displayed. If i remove the IF condition it complains with message "3021 : No current record"

I cant even print the current record when im in the subform to see whats happening.

Can anyone please advice and assist?

Thanks
Rob
 
Hmmm I may add a combo box to allow them select the type of edit mode.

Why something so simple to go to the last record should be this complicated I will never know.

I havent used Access for very long (collectiveily around a month), frustration!
 
Setting the focus to a SubForm is a two step process.
First you must set the focus to the SubFormControl.
Then set the focus to a control on the Form being displayed by the SubFomControl.
Code:
'-- Set Focus to the SubFormControl 1st
Me.SubFormControl.SetFocus
'-- Now set Focus to the control on SubForm
Me.SubFormControl.Form!txtYourControl.SetFocus
'-- And now move to the last record
DoCmd.RunCommand acCmdRecordsGoToLast
...using the name of your controls of course.
 
What about using this simple code after the setFocus command?

Code:
DoCmd.RunCommand acCmdRecordsGoToNew

EDIT: RG beat me to it...

His code will take you to the last visible record - my code will take you to the new blank record.
 
Thanks for all the replies, I was doing some JSP work and now Ive come back to access.

I had read there were issues using DoCmd.RunCommand acCmdRecords from the main form.

Anyway the focus goes to the desired subform.control (I know this as Its the second textbox and not the first).

If there is ONE row within the table it goes to a new record else if there are more it goes to the first record. This is when using acCmdRecordsGoToLast.

Using acCmdRecordsGoToNew results in error "2046: This command or action "RecordsGoToNew" isnt available now".
 
How about posting all of the code you are using to move to the last record? Maybe we'll see something.
 
I just needed to requery the subform !!!!

I'm going to look at changing it to create a new record (with a whole new set of problems no doubt!)
 
It sounds like you are off and running. Have fun.
 

Users who are viewing this thread

Back
Top Bottom