Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2002

    Question Unanswered: Disable All Form Navigation For Editing

    I would like to make a form act like a visual studio form in that I want the form to be initially read-only (AllowEdits No) and allow navigation through the records. If the user wants to edit a record, set AllowEdits to Yes and Lock the form on the current record, until the user either pushes "Submit Changes", pushes "Cancel" or tries to close the form (message box asking if user wants to save the record). I know that just disabling my custom navigation buttons will not be sufficient, as, at the very lease, the mouse-wheel allows navigation when the buttons are disabled. Any help would be greatly appreciated. At the moment I am contemplating just leaving the form read-only and having pop-up forms for edit and new records. My application is in Access 2003 on a Windows 2003 server box. I thank you in advance for your time and your replies.

  2. #2
    Join Date
    Dec 2004
    Madison, WI
    If your form only returns 1 record (ie. opens based on criteria) and you want to prevent the mousewheel from scrolling to a blank record, instead of dealing with a mousewheel.dll and other non-standard MSAccess coding, I'll simply put this code in the OnCurrent event of the Form:

    Private Sub Form_Current()
    End sub

    Essentially this means, if you scroll or go to a new record (OnCurrent), then go back to the first record.

    note: I often find a lot of problems using the mousewheel.dll in a mult-user environment (with connections from several external sources.) It's also problematic with MSAccess upgrading. I personally avoid using the mousewheel.dll in my apps. Still, if you're interested, there are a couple of examples in the code bank.

    Otherwise, I'll store the record ID into a variable and utilize the "FindRecord" command ie. - Docmd.FindRecord MyRecordIDVariable to keep them from scrolling. This can be a little tricky and depends on how you have it designed. Since I usually open a form based on criteria to open a single record (which is less problematic, is much faster, and also allows users to add new records), I only need to use the simple trick above.

    You can also enable/disable the Navigation bar using the below code in the event which opens the form. The key is to manipulate it in the code right after you open the form. You can also set the AllowEdits using the same type of syntax (ie. replace the wording NavigationButtons in the code below with AllowEdits.)

    Private sub cmdEditSubjects_Click()
    Docmd.openform "frmEditSubjects"
    Forms!frmEditSubjects.NavigationButtons = True (or False)
    End Sub

    A lot of times, I'll open the form based on a single record (and thus, can use the first trick above to prevent the scroll):
    Private sub cmdEditSubjects_Click()
    Docmd.openform "frmEditSubjects",,"[RecordID] = " & Forms!MySearchForm!RecordID & ""
    Forms!frmEditSubjects.NavigationButtons = False
    End Sub
    and then again, in the OnCurrent event of the frmEditSubjects:

    Just to add, another trick I do if I only want specific fields to be editable/shown/not shown on the form, is create a box on the form and set it's background to the same color as the form. Then in code I'll make the box visible or invisible (note: bring to Front and set default to invisible.)
    Last edited by pkstormy; 09-25-09 at 20:58.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

Posting Permissions

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