disabling navigation buttons

  • Thread starter Thread starter Bob
  • Start date Start date
B

Bob

I have a form that displays a customer's invoice or invoices. I have
navigation buttons on this form to page through each invoice should the
customer have several. Is there a way to disable these buttons unless the
customer has multiple records?
 
if the form is for *display* purposes only, not add/edit/delete purposes,
then suggest you set the form's RecordsetType property to Snapshot. that
prevents addition (and deletion, and editing) of records; if you can't add a
new record in the form, you can only move between the existing records -
whether it be 1 record or 1 million.

if you want the user to be able to edit/delete records, but not add new
ones, in this form, then instead of the above suggestion, try setting the
form's AllowAdditions property to No. same principal as above - you can only
move between existing records.

hth
 
By default the form has the AllowEdits property set to prevent editing the
data but this is toggled with another button. In either case the buttons I
have to go to next record are displayed whether there is a next record or
not. If none is available, a runtime error occurs. I want to be able to have
the "next record" button become greyed out if there is no next record -
similar to the standard navigation buttons when you reach the last record.
 
If you place the below code into the OnCurrent event of the form in
question and twiddle the button names and their references to match,
you should end up with something useful. Be sure to remove any
references to objects that don't exist in your application.

HTH
 
Ah, yes, the code:

Private Sub Form_Current()
'============================================================
' Purpose: Manage the navigation buttons
' Copyright: Larry Daugherty
' Company: Business Process Solutions
' Programmer: Larry Daugherty
' Called From:
' Date: 11/13/02
' Parameters:
' Notes; REmoved all references to cmdNew s the Edit form
doesn't add records
'============================================================
On Error GoTo Form_Current_Err
Dim strErrMsg As String 'For Error Handling

'Dim recClone As Recordset
Dim recclone As DAO.Recordset

Dim intNewRecord As Integer

'Make a clone of the recordset underlying the form so
'we can move around that without affecting the form's
'recordset
Set recclone = Me.RecordsetClone()
'Set recClone = Me.RecordsetClone

'If this is a new record then disable the <Next> and <New>
'buttons and enable the others. Then exit the procedure.

'The next line requires that there be an autonumber field xxnamexxID
intNewRecord = IsNull(Me.TranscriptID)

If intNewRecord Then
cmdFirst.Enabled = True
cmdNext.Enabled = False
cmdPrevious.Enabled = True
cmdLast.Enabled = True

'Exit Sub
GoTo Form_Current_Exit
End If

'If we reach here, we know we are not in a new record
'so we can enable the <New> button

'But we need to check if there are no records. If so,
'we disable all buttons except for the <New> button

If recclone.RecordCount = 0 Then
cmdFirst.Enabled = False
cmdNext.Enabled = False
cmdPrevious.Enabled = False
cmdLast.Enabled = False
Else

'Synchronise the current pointer in the two recordsets
recclone.Bookmark = Me.Bookmark


'If there are records, see if we are on the first record
'If so, we should disable the <First> and <Prev> buttons

recclone.MovePrevious
cmdFirst.Enabled = Not (recclone.BOF)
cmdPrevious.Enabled = Not (recclone.BOF)
recclone.MoveNext


'And then check whether we are on the last record
'If so, we should disable the <Last> and <Next> buttons

recclone.MoveNext
cmdLast.Enabled = Not (recclone.EOF)
cmdNext.Enabled = Not (recclone.EOF)
recclone.MovePrevious

End If

Form_Current_Exit:
'And finally close the cloned recordset
recclone.Close

'And fire the After_Update events of the comboboxes
cboFindPractitioner_AfterUpdate
cboFindTranscriber_AfterUpdate
cboPatient_AfterUpdate

On Error Resume Next
Exit Sub

Form_Current_Err:
Select Case Err
Case Else
strErrMsg = strErrMsg & "Error #: " & Format$(Err.Number)
& vbCrLf
strErrMsg = strErrMsg & "Error Description: " &
Err.Description
MsgBox strErrMsg, vbInformation, "Form_Current"
Resume Form_Current_Exit
End Select
End Sub
 
Back
Top