PC Review


Reply
Thread Tools Rate Thread

Focus on record in subform

 
 
=?Utf-8?B?QmVubnk=?=
Guest
Posts: n/a
 
      8th Sep 2005
I am using a main form in single view to enter data to a table.
On the main form I have a subform that is a continuous form to show that
data. Both main and subforms have the same RecordSource.

On the main form, After Update event is:
Private Sub Form_AfterUpdate()
Me.Subform.Requery
End Sub
in order to update the subform to show the user what has been entered.
What I want is for the subform to move to the record that was last entered
on the mainform (without the cursor actually staying in the subform) after
the subform has been updated. I'm trying to keep the user from having to
scroll down inside the subform the check on what's been entered. My VB is
quite rusty so sample/generic code would be quite helpful.

Thanks,
Benny


 
Reply With Quote
 
 
 
 
Gijs Beukenoot
Guest
Posts: n/a
 
      8th Sep 2005
From Benny :
> I am using a main form in single view to enter data to a table.
> On the main form I have a subform that is a continuous form to show that
> data. Both main and subforms have the same RecordSource.
>
> On the main form, After Update event is:
> Private Sub Form_AfterUpdate()
> Me.Subform.Requery
> End Sub
> in order to update the subform to show the user what has been entered.
> What I want is for the subform to move to the record that was last entered
> on the mainform (without the cursor actually staying in the subform) after
> the subform has been updated. I'm trying to keep the user from having to
> scroll down inside the subform the check on what's been entered. My VB is
> quite rusty so sample/generic code would be quite helpful.
>
> Thanks,
> Benny


I think the following should do the trick:

dim rsClone as DAO.Recordset
set rsclone = me.<subfornname>.form.recordsetclone
if not rsclone.eof then
rsclone.movelast
me.<subfornname>.form.bookmark = rsclone.bookmark
endif
rsclone.close
set rcslone = nothing


 
Reply With Quote
 
 
 
 
=?Utf-8?B?QmVubnk=?=
Guest
Posts: n/a
 
      13th Sep 2005
Thanks for the suggestion. I should add that my VB programming is not only
rusty, it's not that extensive. Here is how I implemented your suggestion
(Child0 is my subform (it's the only subform in my app)). I don't know if I
inserted the code into the correct spot or not, or if the requery is in the
correct spot etc.

Private Sub Form_AfterUpdate()

Dim rsClone As DAO.Recordset

Me.Child0.Requery

Set rsClone = Me.Child0.Form.RecordsetClone
If Not rsClone.EOF Then
rsClone.MoveLast
Me.Child0.Form.Bookmark = rsClone.Bookmark
End If
rsClone.Close
Set rcslone = Nothing
End Sub

The result I get is that the subform moves to the last record in the
underlying table. I would like to get it to move to the last record entered
into the table, via the mainform. Don't know if it makes a difference, but
the table is ordered by UnitNumber for the purpose of easier viewing. This
appears to be a little over my head, so don't be shy about "talking down" to
me. Thanks for any and all help.

Benny
 
Reply With Quote
 
Gijs Beukenoot
Guest
Posts: n/a
 
      13th Sep 2005
From Benny :
> Thanks for the suggestion. I should add that my VB programming is not only
> rusty, it's not that extensive. Here is how I implemented your suggestion
> (Child0 is my subform (it's the only subform in my app)). I don't know if I
> inserted the code into the correct spot or not, or if the requery is in the
> correct spot etc.
>
> Private Sub Form_AfterUpdate()
>
> Dim rsClone As DAO.Recordset
>
> Me.Child0.Requery
>
> Set rsClone = Me.Child0.Form.RecordsetClone
> If Not rsClone.EOF Then
> rsClone.MoveLast
> Me.Child0.Form.Bookmark = rsClone.Bookmark
> End If
> rsClone.Close
> Set rcslone = Nothing
> End Sub
>
> The result I get is that the subform moves to the last record in the
> underlying table. I would like to get it to move to the last record entered
> into the table, via the mainform. Don't know if it makes a difference, but
> the table is ordered by UnitNumber for the purpose of easier viewing. This
> appears to be a little over my head, so don't be shy about "talking down" to
> me. Thanks for any and all help.
>
> Benny


Well, in the example I gave, the recordpointer always goes to the last
record, correct. Based on the assumption that the sort-order of that
form would be equal to the 'number' that the users entered would be
incrementing and thus will always be the last one.

If you want to go to a specific record, you'll have to change the
movelast to a findfirst and pass the number that the user entered in
the mainform.
In other words, if you're user enters UnitNumber as the unique
identifier and UnitNumber is also the fieldname on the form, you can
use that field in the example below. Otherewise, find another unique
field to search on.

rsClone.FindFirst("UnitNumber=" & CStr(Me.UnitNumber)) 'or
Forms!<MainFormName>.UnitNumber if you're not on the form where the
control resides
If Not rsClone.NoMatch Then
'Records is found, set the bookmark
Me.Child0.Form.Bookmark = rsClone.Bookmark
else
MsgBox "Corresponding record not found in the subform", vbexclamation
+ vbokonly 'Or some more meaningfull message
endif

Keep in mind that this will only work after the record is added to the
table, otherwise the record will never be found and the recordpointer
isn't moved. The same goes when the user deletes a record...

Also note that searching large recordsets can take a while and not
having an index on the field you're searching will increase the
searchtime...


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Double click record in subform to go to new record in Main (and subform) Jpipher@gmail.com Microsoft Access 14 3rd Feb 2007 08:06 AM
Wierd subform behaviour, subform not cycling through after updating a subform record Mikal Microsoft Access Forms 2 25th May 2006 07:15 PM
Subform, new record, Focus goes to last field on next subform entry Nigel Greenwood via AccessMonster.com Microsoft Access Forms 1 7th May 2005 01:20 PM
code to delete a record in one subform when a record in a related subform is deleted Helen Microsoft Access Form Coding 3 3rd Apr 2005 10:01 PM
Urgent !!! - Values from Subform - #Error if no records in Subform and Only grabs first subform record Greg Microsoft Access Forms 0 17th Feb 2005 02:12 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:46 PM.