2007 and moving to last record on subform

2007 and moving to last record on subform

am 24.10.2007 18:55:50 von arthur.dayton

I am using Access 2007. I'm trying to set the [End Time] control on a
subform to the current time. My code is:

Private Sub Command7_Click()
With Me.[frm_Time_subform]
..Form.SetFocus
..Form![End Time].SetFocus
RunCommand acCmdRecordsGoToLast
..Form![End Time] = Now()
End With
End Sub

Problem is I get this error message:

Run-Time error '2449
There is an invalid method in an expression.

Debug takes me to the .Form.SetFocus line.

If I remove the line the code runs and takes me to the last record in
the main form and sets the [End Time] value to the current time or if
I remove the RunCommand acCmdRecordsGoToLast command it changes the
end time inthe first record of the subform.

Can anyone help?

Re: 2007 and moving to last record on subform

am 24.10.2007 20:16:37 von Salad

arthur.dayton@kiewit.com wrote:

> I am using Access 2007. I'm trying to set the [End Time] control on a
> subform to the current time. My code is:
>
> Private Sub Command7_Click()
> With Me.[frm_Time_subform]
> .Form.SetFocus
> .Form![End Time].SetFocus
> RunCommand acCmdRecordsGoToLast
> .Form![End Time] = Now()
> End With
> End Sub
>
> Problem is I get this error message:
>
> Run-Time error '2449
> There is an invalid method in an expression.
>
> Debug takes me to the .Form.SetFocus line.
>
> If I remove the line the code runs and takes me to the last record in
> the main form and sets the [End Time] value to the current time or if
> I remove the RunCommand acCmdRecordsGoToLast command it changes the
> end time inthe first record of the subform.
>
> Can anyone help?
>

This is an alternative method
Dim rst As Recordset
Set rst = Me.[frm_Time_subform].Form.Recordsetclone
If rst.recordcount > 0 then
rst.moveLast
rst.edit
rst![End Time] = Now()
rst.update
Me.[frm_Time_subform].Form.Bookmark = rst.bookmark
Endif
set rst = Nothing

set rst = Nothing

Re: 2007 and moving to last record on subform

am 25.10.2007 06:11:59 von Allen Browne

Remove the ".Form" from the first Setfocus, i.e.:
.SetFocus

That way the subform control becomes the active control of the main form.
Your next line then makes the End Time text box the active control within
the subform.

It should not change all rowsm unless the End Time is unbound.
Sounds a bit apocalyptic. :-)

--
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.

wrote in message
news:1193244950.726572.85890@z24g2000prh.googlegroups.com...
>I am using Access 2007. I'm trying to set the [End Time] control on a
> subform to the current time. My code is:
>
> Private Sub Command7_Click()
> With Me.[frm_Time_subform]
> .Form.SetFocus
> .Form![End Time].SetFocus
> RunCommand acCmdRecordsGoToLast
> .Form![End Time] = Now()
> End With
> End Sub
>
> Problem is I get this error message:
>
> Run-Time error '2449
> There is an invalid method in an expression.
>
> Debug takes me to the .Form.SetFocus line.
>
> If I remove the line the code runs and takes me to the last record in
> the main form and sets the [End Time] value to the current time or if
> I remove the RunCommand acCmdRecordsGoToLast command it changes the
> end time inthe first record of the subform.
>
> Can anyone help?
>