Rabu, 03 Agustus 2011

Re: [MS_AccessPros] Focus on last record in a subform after update of field in unbound main form.

 

Hi Connie,

does the combobox filter the subform? If so, a requery should be done on the AfterUpdate of the combo, then move the focus. Here is code I put into a general module to move to the last record. You send the form reference as a parameter -- so you can make it move to the last record on any open form.

'~~~~~~~~~~~~~~~~~~~~~~~~~~ RecordLast
Function RecordLast(Optional pF As Form _
, Optional pFirstControlName As String = "") As Byte
'Crystal strive4peace

'example useage: OnClick event of a Go To Last Record command button
' = RecordLast()
' = RecordLast([Form])
' = RecordLast([Form], "Controlname")

On Error Resume Next
If pF Is Nothing Then Set pF = Screen.ActiveForm

'if there have been changes to the current record, save them
If pF.Dirty Then pF.Dirty = False: DoEvents

If pF.Recordset.RecordCount > 0 Then
pF.Recordset.MoveLast
If pFirstControlName <> "" Then
pF(pFirstControlName).SetFocus
End If
End If

End Function

'~~~~~~~~~~~~~~~~~~~~~~

in your code, call it like this:

with Me.subform_controlname
.SetFocus
'.Requery 'commented since you may not need this
'call Crystal's generic code
RecordLast .Form, "controlname_setfocus"
end with

WHERE
subform_controlname is the Name property of the subform control where you want to move
controlname_setfocus is optional -- if specified, it is the Name in quotes of the control on the subform that you want to get the focus (ie: the first control)

Warm Regards,
Crystal

*
(: have an awesome day :)
*

--- On Wed, 8/3/11, mrsgoudge wrote:

> Good afternoon! 
>
> Main Form is unbound: "Search_HomeInfo"
> SubForm: "Search_HomeInfoSub_Listing".  Is ordered by
> date upon opening. 
>
> In the after update event of a combobox in the main form's
> header I would like the focus to go to the last record in
> the subform.  I have tried many combinations and erased
> all of them.  I have put the code for this event below
> without any of the things I've tried to make this
> happen. 
>
> Thanks :-)
> Connie
>
> Private Sub cboAddress_AfterUpdate()
> On Error GoTo Proc_Err
>    
>    
> '***********************************************************************
>     'Set the Master/Child Fields based upon the
> info entered in the header
>    
> '***********************************************************************
> Me.cboParcelN = ""
> Me.tbHomeInfoID = Me.cboAddress.Column(0)
>
> Proc_Exit:
>     Exit Sub        ' or Exit
> Function
>
> Proc_Err:
>     MsgBox Err.Description, , _
>            "ERROR "
> & Err.Number _
>            &
> "   cboAddress_AfterUpdate"
>
>     Resume Proc_Exit
>
>     'if you want to single-step code to find
> error, CTRL-Break at MsgBox
>     'then set this to be the next statement by
> right-clicking on Resume Statement, then press F8 to execute
> one line at a time
>     Resume
>
> End Sub
>
>

__._,_.___
Recent Activity:
.

__,_._,___

Tidak ada komentar:

Posting Komentar