Selasa, 01 Oktober 2013

[MS_AccessPros] RE: RE: Enable and Disable the First and Last navigation cmdbuttons

 

Phucon


I always put a text box named txtFocus on my form just in case one of the buttons has focus. txtFocus is a tiny box  Width & Height set to something like 0.0007 with a transparent border and back. You could use cmdClose instead but that button actually does something so you might be causing yourself grief if you use that to set focus.


Bill



---In MS_Access_Professionals@yahoogroups.com, <ms_access_professionals@yahoogroups.com> wrote:

 

Thank you Bill, that's smart code. Using yours saves me lines (my own method has more than 20 lines) of code.

One thing I don't quit get it, is the "frm.txtFocus.SetFocus". I am wondering if it is the same if the focus is set onto any other controls (I have not tried it), cmdClose for example.

Thank again Bill

Phucon



---In ms_access_professionals@yahoogroups.com, <wrmosca@...> wrote:

Phucon


This is how I do it:


'Form's current event:


Private Sub Form_Current()

    Call CheckPosition(Me)

    Me.lblRecCt.Caption = Me.CurrentRecord & " of " & Me.Recordset.RecordCount


End Sub



'Public routine called by all forms as needed. Occasionally, I need to pass

'an array of controls to re0query, but not very often.

Public Sub CheckPosition(frm As Form, ParamArray ctrls())

'Purpose  : Enable/disable nav buttons.

'           txtFocus is a textbox that is used only to get

'           Focus during enabling/disabling. It is just a

'           dot on the form placed near nav buttons.

'DateTime : 11/29/2006 07:50

'Author   : Bill Mosca

    Dim lngRecNum As Long

    Dim lngRecCt As Long

    Dim x As Integer

    

    

    lngRecNum = frm.CurrentRecord

    '    frm.RecordsetClone.MoveFirst

    If lngRecNum < frm.Recordset.RecordCount Then

        frm.RecordsetClone.MoveLast

    End If

    lngRecCt = frm.RecordsetClone.RecordCount

    frm.txtFocus.SetFocus

    frm.cmdGoFirst.Enabled = lngRecNum <> 1

    frm.cmdGoPrev.Enabled = lngRecNum <> 1

    frm.cmdGoNext.Enabled = lngRecNum < lngRecCt

    frm.cmdGoLast.Enabled = lngRecNum < lngRecCt

    frm.cmdGoNew.Enabled = frm.Recordset.RecordCount <> 0

    

    'No Additions should disable "New" button

    If frm.AllowAdditions = False Then

        frm.cmdGoNew.Enabled = False

    Else

        frm.cmdGoNew.Enabled = frm.Recordset.RecordCount <> 0

    End If


    'If any cbo's or lst's have a user-defined function for RowSourceType

    'they will need to be requeried.

    If Not IsNull(ctrls) Then

        For x = 0 To UBound(ctrls)

            If ctrls(x).ControlSource = "" Then ctrls(x) = Null

            ctrls(x).Requery

        Next

    End If


End Sub


Regards,

Bill Mosca, Founder - MS_Access_Professionals

http://www.thatlldoit.com

Microsoft Office Access MVP

https://mvp.support.microsoft.com/profile=C4D9F5E7-BB03-4291-B816-64270730881E

My nothing-to-do-with-Access blog

http://wrmosca.wordpress.com


 



---In MS_Access_Professionals@yahoogroups.com, <ms_access_professionals@yahoogroups.com> wrote:

I use these 2 statements to Enable and Disable the First and Last navigation cmdbuttons. The syntext looks weir to me, but it works ok so far. Is it an appropriate way?  What are other alternatives?

With Me

    !lblTotRec.Caption = "Record " & rs.AbsolutePosition + 1 & " of  " & rs.RecordCount

    !cmdLast.Enabled = Not Me.CurrentRecord = rs.RecordCount               

    !cmdFirst.Enabled = Not rs.AbsolutePosition + 1 = 1

End With

Thanks

Phucon

__._,_.___
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (4)
Recent Activity:
.

__,_._,___

Tidak ada komentar:

Posting Komentar