Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2005
    Posts
    2

    Question Unanswered: How to capture when moving between records displayed on a form?

    Hello once more.

    I have created a form that displays the records of a table.
    By default, the form is set to :
    Code:
    AllowEdits = False
    AllowDeletions = False
    AllowAdditions = False
    Therefore the user can only view/browse the existing records.
    If the user wants to modify or create a new record he has to press a specific button that will modify the relevant property of the form.

    Here how I wish that it would work:
    If the user presses the Edit/Modify button or the Create New Record button and does not edit/modify anything then I wish the properties to be set as they were so he can't accidently modify something. My problem is that I can't get to capture whether the user has moved between records using the BeforeUpdate() event.

    So is there any way I could capture this even if the user does not modify anything?

    I am using Microsoft Access 2000 (9.0.6926 SP-3).

    Thanks in advance.

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    you need to look at the form events.. forget which but its soemthing like on change or beforemove

    ...jsut checked its oncurrent or form.current
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Apr 2004
    Location
    Derbyshire, UK
    Posts
    789
    Provided Answers: 1
    Hi

    Would this do the job

    Code:
    Private Sub Form_Current()
        Me.AllowAdditions = False
        Me.AllowEdits = False
        Me.AllowDeletions = False
    End Sub
    this resets the properties wether or not anything has been changed ?

    MTB

  4. #4
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Assuming the OP has something like this to add a new record

    Code:
     Me.AllowAdditions = True
        DoCmd.GoToRecord , , acNewRec
    The code
    Code:
    Private Sub Form_Current()
        Me.AllowAdditions = False
        Me.AllowEdits = False
        Me.AllowDeletions = False
    End Sub
    is not going to allow a new record, it'll give a "You can't go to the record" error message.

    What they need to do is reset the properties to False after the new record is saved (or after the record is edited or deleted) so they need to put this code, I think, in the form's AfterUpdate event

    Code:
    Private Sub Form_AfterUpdate()
      Me.AllowAdditions = False
      Me.AllowEdits = False
      Me.AllowDeletions = False
    End Sub
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  5. #5
    Join Date
    Apr 2004
    Location
    Derbyshire, UK
    Posts
    789
    Provided Answers: 1
    Hi

    Missinglinq beat me to it, but for what it's worth this is what I came up with
    Code:
    Private Sub cmdEdit_Click()
        Me.AllowAdditions = True
        Me.AllowEdits = True
        Me.AllowDeletions = True
    End Sub
    
    Private Sub Form_Current()
        If Not Me.NewRecord Then
            Me.AllowAdditions = False
            Me.AllowEdits = False
            Me.AllowDeletions = False
        End If
    End Sub
    Private Sub cmdAdd_Click()
    On Error GoTo Err_cmdAdd_Click
    
        Me.AllowAdditions = True
        
        DoCmd.GoToRecord , , acNewRec
    
    Exit_cmdAdd_Click:
        Exit Sub
    
    Err_cmdAdd_Click:
        MsgBox Err.Description
        Resume Exit_cmdAdd_Click
        
    End Sub
    Assuming we have an Edit and Add button on the form.


    MTB

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •