Applecore Pages on Microsoft Access

Changing the current Form to allow Edits

If you want to limit edits to a form's data, you can open the form and have AllowEdits set to False for the form. However, if you then want to allow the user to be able to edit data that is displayed on the form, you will need to have a mechanism for allowing this to happen without the user having to close the form and open it again. The solution is to have a command button on the form, which has the following code in its OnClick event:

Private Sub cmdEdit_Click()
    Dim ctl As Control
    Dim lngBackColor As Long
    Me.AllowEdits = Not (Me.AllowEdits)
    If Me.AllowEdits = True Then
        Me!cmdEdit.Caption = "Lock"
        lngBackColor = vbGreen
    Else
        Me!cmdEdit.Caption = "Edit"
        lngBackColor = vbWhite
    End If
    For Each ctl In Me.Controls
        If TypeOf ctl Is TextBox Or TypeOf ctl Is ComboBox Then
            ctl.BackColor = lngBackColor
        End If
    Next ctl
End Sub

As well as changing the AllowEdits property, I also tend to change the back colour of controls, in order to make it more obvious to the user of the change. I also change the caption of the command button from "Edit" to "Lock" to make sense to the user.

Top

 


HOME | NEW | TABLES | QUERIES | FORMS | REPORTS | GENERAL | API | DOWNLOADS | TUTORIAL | RESOURCES
E-MAIL
Copyright & Disclaimer

 

Last modified at 06/06/2006 14:54:54