Results 1 to 6 of 6
  1. #1
    vector39 is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    May 2017
    Posts
    76

    Need help on how users can only use search bar on form but cannot edit records

    Hi all



    I have a search bar that filters a datasheet on split form view and works very nicely. I made an exact copy of this however, the original form the user can edit and make changes if necessary, this copy will only be used for looking up records AND NOT EDITING. Here's the VBA for the search bar:
    Code:
    Option Compare Database
    Option Explicit
    
    
    Private Sub cmdReset_Click()
    Me.txtSearch = ""
        Me.SrchText = ""
        DoCmd.Requery
        Me.txtSearch.SetFocus
    End Sub
    
    
    
    
    Private Sub Form_Load()
    'DoCmd.GoToRecord , , acNewRec
    End Sub
    
    
    
    
    Private Sub SrchText_AfterUpdate()
    Me.SrchText.Requery
    End Sub
    
    
    Private Sub txtSearch_Change()
    'Create a string (text) variable
    
    
        Dim vSearchString As String
        vSearchString = txtSearch.Text
        SrchText.Value = vSearchString
        If Len(Me.SrchText) <> 0 And InStr(Len(SrchText), SrchText, " ", vbTextCompare) Then
            Exit Sub
            End If
        'Me.SearchResults = Me.SearchResults.ItemData(1)
        
        'Me.SearchResults.SetFocus
        DoCmd.Requery
        Me.txtSearch.SetFocus
        If Not IsNull(Len(Me.txtSearch)) Then
            Me.txtSearch.SelStart = Len(Me.txtSearch)
            End If
    End Sub
    I'm just trying to find the simplest way where users can still use the search bar just not edit anything in the datasheet. I'm pretty sure there is something on the form properties that I can change but I've been messing around with it and so far, I can either not type anything it at all or I can still edit records on this copy. Any thoughts, as always, much appreciated!

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    set the form properties:
    RECORDSET TYPE = SNAPSHOT

    or
    ALLOW EDITS = FALSE
    ALLOW ADDITIONS = FALSE

    or
    lock the form
    DOCMD.OpenForm "FORM",,,,acFormReadOnly

  3. #3
    vector39 is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    May 2017
    Posts
    76
    Quote Originally Posted by ranman256 View Post
    set the form properties:
    RECORDSET TYPE = SNAPSHOT

    or
    ALLOW EDITS = FALSE
    ALLOW ADDITIONS = FALSE

    or
    lock the form
    DOCMD.OpenForm "FORM",,,,acFormReadOnly
    I tried each method. Switching Dynaset to Snapshot, gave me an error with the vba. I set Allow Additions/Edits both to False however I could not type anything in the search bar anymore and same thing with DoCmd.OpenForm "Form",,,,acFormReadOnly.

  4. #4
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    In form design view, set the "Locked" property to YES for EACH control you do not want to be editable.
    You can still tab/click into each control; if you don't want anyone to be able to tab/click into a control, set the "Enabled" property to NO.

    Obviously, for the control "SrchText", the "Locked" property should be NO and the "Enabled" property to YES....

    Leave these form properties set to:
    RECORDSET TYPE = Dynaset
    ALLOW EDITS = Yes
    ALLOW ADDITIONS = Yes

  5. #5
    vector39 is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    May 2017
    Posts
    76
    Quote Originally Posted by ssanfu View Post
    In form design view, set the "Locked" property to YES for EACH control you do not want to be editable.
    You can still tab/click into each control; if you don't want anyone to be able to tab/click into a control, set the "Enabled" property to NO.

    Obviously, for the control "SrchText", the "Locked" property should be NO and the "Enabled" property to YES....

    Leave these form properties set to:
    RECORDSET TYPE = Dynaset
    ALLOW EDITS = Yes
    ALLOW ADDITIONS = Yes

    Thank you!

  6. #6
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    You're welcome...

    Good luck with your project....

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Access Design and Form - Search, Add, Edit
    By kwarden13 in forum Database Design
    Replies: 16
    Last Post: 02-29-2016, 08:39 AM
  2. Search form with a Edit Button
    By gebmiller1984 in forum Forms
    Replies: 5
    Last Post: 02-14-2015, 11:54 AM
  3. Search/Edit form creation
    By Hagridore in forum Forms
    Replies: 11
    Last Post: 01-21-2015, 11:17 PM
  4. Replies: 1
    Last Post: 07-10-2014, 03:09 PM
  5. Replies: 21
    Last Post: 08-05-2013, 06:23 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums