Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access thread: After editcmd


Message #1 by "KennethMungwira" <KennethMungwira@Y...> on Fri, 19 Oct 2001 18:49:08
Dear sir or madam,

Below is code that when freezes a form and only lets you edit it when the 

edit function is run. Unfortunately, the save button retrieves the 

information saved from the previous save function, thus you can only edit 

one record at a time(then exit the form and return to edit another 

record). How can I avoid this problem.







Option Compare Database

Option Explicit



Private Sub FormPermits(bolOK As Boolean)



    With Me

        .AllowEdits = bolOK

        !subDateForm.Form.AllowEdits = bolOK

        !subDateForm.Form.AllowAdditions = bolOK

        !subDateForm.Form.AllowDeletions = bolOK

        !Profile.Form.AllowEdits = bolOK

        !Profile.Form.AllowAdditions = bolOK

        !Profile.Form.AllowDeletions = bolOK

        !ICsubStatusInfo.Form.AllowEdits = bolOK

        !ICsubStatusInfo.Form.AllowAdditions = bolOK

        !ICsubStatusInfo.Form.AllowDeletions = bolOK

    End With

    RefID.SetFocus

    ' Make the cmdSave button visible

    cmdSave.Visible = bolOK





End Sub



Private Sub cmdEditUndo_Click()

On Error GoTo Err_cmdEditUndo_Click

    

    Dim ctl As Control

    With cmdEditUndo

        If .Caption = "Change This Record" Then

            ' Change the font color and caption

            ' of the cmdEditUndo button

            .Caption = "Undo All Changes"

            .ForeColor = vbRed

            ' Change the caption of the form Headers

            lblHeader1.Caption = "Edit this TSR Record"

            lblHeader2.Caption = "Edit this TSR Record"

            ' Allow editing of the main and sub forms

            Call FormPermits(True)

            ' Copy the data from each combobox's and textbox's

            ' Control Source property to each control's

            ' tag property

            For Each ctl In Me.Controls

                Select Case ctl.ControlType

                    Case acComboBox, acTextBox

                        If Not IsNull(ctl) Then

                            ctl.Tag = ctl

                        End If

                End Select

            Next ctl

            ' Do the same for the subform's fields

            For Each ctl In Me!subDateForm.Form

                Select Case ctl.ControlType

                    Case acComboBox, acTextBox

                        If Not IsNull(ctl) Then

                            ctl.Tag = ctl

                        End If

                End Select

            Next ctl

            For Each ctl In Me!ICsubStatusInfo.Form

                Select Case ctl.ControlType

                    Case acComboBox, acTextBox

                        If Not IsNull(ctl) Then

                            ctl.Tag = ctl

                        End If

                End Select

            Next ctl

            For Each ctl In Me!Profile.Form

                Select Case ctl.ControlType

                    Case acComboBox, acTextBox

                        If Not IsNull(ctl) Then

                            ctl.Tag = ctl

                        End If

                End Select

            Next ctl

         Else

            ' Change the font color and caption

            ' of the cmdEditUndo button

            .Caption = "Change This Record"

            .ForeColor = vbBlue

            ' Change the caption of the form Headers

            lblHeader1.Caption = "View TSR Data Only"

            lblHeader2.Caption = "View TSR Data Only"

            ' Undo any changes by copying the data from

            ' the control's Tag property to the control's

            ' Control Source property

            For Each ctl In Me.Controls

                Select Case ctl.ControlType

                    Case acComboBox, acTextBox

                        If Len(ctl.Tag) > 0 And ctl.Name <> "CommonID" Then

                            ctl = ctl.Tag

                        End If

                End Select

            Next ctl

            ' Do the same for the subform's fields

            For Each ctl In Me!ICsubStatusInfo.Form

                Select Case ctl.ControlType

                    Case acComboBox, acTextBox

                        If Len(ctl.Tag) > 0 Then

                            ctl = ctl.Tag

                        End If

                End Select

            Next ctl

            For Each ctl In Me!subDateForm.Form

                Select Case ctl.ControlType

                    Case acComboBox, acTextBox

                        If Len(ctl.Tag) > 0 Then

                            ctl = ctl.Tag

                        End If

                End Select

            Next ctl

            For Each ctl In Me!Profile.Form

                Select Case ctl.ControlType

                    Case acComboBox, acTextBox

                        If Len(ctl.Tag) > 0 Then

                            ctl = ctl.Tag

                        End If

                End Select

            Next ctl

            ' Do not allow editing of the main and sub forms

            Call cmdSave_Click

 '           Call FormPermits(False)

        End If

    End With

    

Exit_cmdEditUndo_Click:

    

    Exit Sub



Err_cmdEditUndo_Click:

    MsgBox Err.Description

    Resume Exit_cmdEditUndo_Click

    

End Sub



Private Sub Form_BeforeUpdate(Cancel As Integer)

Me.txtNTID.Value = GetNTUserID

End Sub



Private Sub Form_Current()

On Error GoTo Form_Current_ERR

    ' Change the cmdEditUndo caption and

    ' font color.  Change the form's headers

    ' captions and do not permit editing of

    ' any records when we move to another

    ' record.

    

    If Me.AllowAdditions Then

        cmdEditUndo.Visible = False

        lblHeader1.Caption = "Add TSR Data Only"

        lblHeader2.Caption = "Add TSR Data Only"

        lblEditOnly.Visible = False

    ElseIf Me.AllowEdits Then

        Call FormPermits(False)

        With cmdEditUndo

            .Caption = "Change This Record"

            .ForeColor = vbBlue

        End With

        ' Hide the cmdSave button if it is visible

        cmdSave.Visible = False

        lblHeader1.Caption = "View TSR Data Only"

        lblHeader2.Caption = "View TSR Data Only"

        Me.AllowEdits = False

    End If

    

Form_Current_EXIT:

    Exit Sub

    

Form_Current_ERR:

    MsgBox Err.Description

    Resume Form_Current_EXIT



End Sub

Private Sub cmdClose_Click()

On Error GoTo Err_cmdClose_Click



    DoCmd.Close



Exit_cmdClose_Click:

    Exit Sub



Err_cmdClose_Click:

    MsgBox Err.Description

    Resume Exit_cmdClose_Click

    

End Sub



Private Sub cmdSave_Click()

On Error GoTo Err_cmdSave_Click



    DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

    With cmdEditUndo

        .Caption = "Change This Record"

        .ForeColor = vbBlue

    End With

    lblHeader1.Caption = "View TSR Data Only"

    lblHeader2.Caption = "View TSR Data Only"

    Call FormPermits(False)

'    Me.AllowEdits = False

    

Exit_cmdSave_Click:

    

'    RefID.SetFocus

    cmdSave.Visible = False

    Exit Sub



Err_cmdSave_Click:

    MsgBox Err.Description

    Resume Exit_cmdSave_Click

    

End Sub


  Return to Index