Kamis, 02 April 2015

[MS_AccessPros] Re: Issue display vba nav controls

 

Thanks for the reply John.  That got the display working with one exception: the last record is always selected and the nav buttons don't allow changing the selected record.  Count is good but only last record can be viewed.

Rod



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

Rod-

The problem is probably that RecordCount is not yet accurate when the code runs.  Until you've navigated to the last record, it won't contain the total count.  Try this:

Private Sub Form_Current()
Dim tmpRcdCnt As Long
Dim tmpCurrentRcd As Long
Dim rstTemp As DAO.Recordset
    On Error Resume Next
    Set rstTemp = Me.RecordsetClone
    ' Got to the last record to ensure an accurate count
    rstTemp.MoveLast
    tmpRcdCnt = rstTemp.RecordCount
    Set rstTemp = Nothing
    tmpCurrentRcd = Me.CurrentRecord
    If tmpRcdCnt < 2 Then
       Me.FormFooter.Visible = False
       Exit Sub
    Else
       Me.FormFooter.Visible = True
    End If
    If tmpCurrentRcd = 1 Then
        Me.CmdBack.Enabled = False
    Else
        Me.CmdBack.Enabled = True
    End If
    If tmpCurrentRcd = tmpRcdCnt Then
    Else
    End If
    If tmpCurrentRcd >= tmpRcdCnt Then
        Me.CmdNext.Enabled = False
    Else
        Me.CmdNext.Enabled = True
    End If
    Me.LblrecordCounter.Caption = _
             "Record " & tmpCurrentRcd & " of " & tmpRcdCnt
End Sub


John Viescas, Author
Microsoft Access 2010 Inside Out
Microsoft Access 2007 Inside Out
Microsoft Access 2003 Inside Out
Building Microsoft Access Applications 
SQL Queries for Mere Mortals 
(Paris, France)




On Apr 2, 2015, at 5:21 AM, desertscroller@... [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:

Good Evening All,
Having an issue of displaying navigation buttons and text string of
x of xx records.
The following code is used:

Private Sub Form_Current()
Dim tmpRcdCnt As Long
Dim tmpCurrentRcd As Long
    On Error Resume Next
    tmpRcdCnt = Me.Recordset.RecordCount
    tmpCurrentRcd = Me.CurrentRecord
    If tmpRcdCnt < 2 Then
       Me.FormFooter.Visible = False
       Exit Sub
    Else
       Me.FormFooter.Visible = True
    End If
    If tmpCurrentRcd = 1 Then
        Me.CmdBack.Enabled = False
    Else
        Me.CmdBack.Enabled = True
    End If
    If tmpCurrentRcd = tmpRcdCnt Then
    Else
    End If
    If tmpCurrentRcd >= tmpRcdCnt Then
        Me.CmdNext.Enabled = False
    Else
        Me.CmdNext.Enabled = True
    End If
    Me.LblrecordCounter.Caption = _
             "Record " & tmpCurrentRcd & " of " & tmpRcdCnt
End Sub

When the code is single stepped everything works great but at normal speed
the nav buttons and caption do not appear.  There are at least 3 records
in the record source.  FYI this is in one subform and a duplicate in a
secord subform (2nd form has 2 records).  The subforms are used to compare
entries and decisions are made on the differences (update first form with
data from second form, include the 2nd form's record into the 1st form, or
ignore the 2nd form's data).   Nav controls located in footer.

Is there something I am missing when trying to display the nav controls?
Using Access 2010 on Windows 7 and 8.1.

Rod



__._,_.___

Posted by: desertscroller@cox.net
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (3)

.

__,_._,___

Tidak ada komentar:

Posting Komentar