Newbie: Browsing/Editing Forms

ianforest

Registered User.
Local time
Today, 14:52
Joined
Oct 14, 2003
Messages
17
In my bookings form, I want all the fields to be greyed out (i.e. non editable) unless an 'edit' button is clicked, and then greyed out again when 'save' is clicked.

Obviously, I don't want any entries greyed out when adding a new record.

Is this easy to do? How would I do this? Would it be easier to have 2 forms? One for browsing/edit and one for new records, or maybe just one for browsing and one for edit/add new.

Many thanks in advance!
 
The simplest way is:

Put an asterisk in the Tag property of the controls you want to disable

Then have a look at this code:

Code:
Private Sub Form_Current()
    If Me.NewRecord ' test if new record
        Call EnableControls(True)
    Else
        Call EnableControls(False)
    End If
End Sub

Private Sub cmdEdit_Click()
    Call Form_Current()
End Sub

Private Sub cmdSave_Click()
    DoCmd.SaveRecord acCmdSaveRecord
    Call Form_Current()
End Sub


Private Sub EnableControls(ByVal boo As Boolean)
    Dim ctl As Control
    For Each Control In Me
        If ctl.Tag = "*" Then
            ctl.Enabled = boo
            ctl.Locked = Not boo
        End If
    Next
End Sub
 

Users who are viewing this thread

Back
Top Bottom