Good morning all,
I am asking some advise more than anything in this post. I use the code below in most every form i make. Would it be considered good programing to just make a module and put this is as public subs and call for it in on current or would this be a bad idea. I only ask as I don't know! I just seems to me that this should go into a module. And if so, how would I create a variable in the form name for the error code to specify the form that it is using? I didn't put the code in for the First, Last, Prev, and Next but I would also do that. Just didn't want to paste all that code, please assume it goes in too as public subs.
Thank you,Code:Private Sub Form_Current() Dim rst As DAO.Recordset Dim nCount As Integer, nPosition As Integer nCount = Me.Recordset.RecordCount On Error GoTo Err_Handler If nCount = 0 Then MsgBox "No Records exist yet.", vbOKOnly, " R E S T R I C T I O N " Exit Sub End If Set rst = Me.RecordsetClone rst.MoveLast rst.MoveFirst nCount = rst.RecordCount nPosition = Me.CurrentRecord Me!TxtRecordNo = nPosition & " of " & nCount CmdFirst.Enabled = True CmdPrev.Enabled = True CmdNext.Enabled = True CmdLast.Enabled = True 'disable as appropriate If nCount = 1 Then CmdFirst.Enabled = False CmdPrev.Enabled = False CmdNext.Enabled = False CmdLast.Enabled = False ElseIf nPosition = 1 Then CmdFirst.Enabled = False CmdPrev.Enabled = False ElseIf nPosition = nCount Then CmdLast.Enabled = False CmdNext.Enabled = False End If Exit_Handler: If Me.Dirty Then Me.Dirty = False Set rst = Nothing Exit Sub Err_Handler: Select Case Err Case Else MsgBox "Error " & Err & ": " & Error$, vbExclamation, "Form_Current()" Resume Exit_Handler End Select End Sub
Dave