Results 1 to 13 of 13
  1. #1
    Scott_80 is offline Novice
    Windows XP Access 2003
    Join Date
    Jan 2012
    Posts
    5

    Lock control after data entry

    Hello, I'm running Access 2003 on a WinXp machine. On a form I created, I need to have a control(field) locked after data is entered in it. But also able to have data entered in the same control-field when scrolling to the next record(page). Any ideas on VB scripting would be greatly appreciated, thank you.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You would use code in the after update event of the control to lock it, and similar code in the current event of the form to handle the changing of records (or cleaner, a function called by both). The test would look like:

    If Len(Me.SomeControl & vbNullString) = 0 Then

    which tests to see if something is entered in the control.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Scott_80 is offline Novice
    Windows XP Access 2003
    Join Date
    Jan 2012
    Posts
    5
    Ok I entered this script into the VB fields of Current and AfterUpdate, but I'm getting error: Block If without End If.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    That was just the test. The full bit would look like:

    Code:
    If Len(Me.SomeControl & vbNullString) = 0 Then
      Me.SomeControl.Locked = False
    Else
      Me.SomeControl.Locked = True
    End If
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    Scott_80 is offline Novice
    Windows XP Access 2003
    Join Date
    Jan 2012
    Posts
    5
    Ok that made some progress as far as not being able to change the control data. However I now cannot add data to that control field when scrolling to the next record page. I put this script in the AfterUpdate section by the way.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Did you add it to the current event as suggested?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    Scott_80 is offline Novice
    Windows XP Access 2003
    Join Date
    Jan 2012
    Posts
    5
    I added it to the AfterUpdate section. Does it need to be in both Current event and AfterUpdate event?

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    As I said in post 2, yes.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    Scott_80 is offline Novice
    Windows XP Access 2003
    Join Date
    Jan 2012
    Posts
    5
    Ok looks like that works. Thank you very much for your help.

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No problem.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  11. #11
    scharj01 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2015
    Posts
    2
    First of all , I apologize for being a such a novice.
    This code works for the Combo box (List 168) , which is a table look up , but not for the Text box(Project Number) field which is driect entry.
    Both The fileds are locked after entry. List168 works perfectly , but for the Project_Number I get a "Run time error 424 Object required" as soon as I select Add new record. I have added it in both Current event and AfterUpate.
    If Len(List168 & vbNullString) = 0 Then
    List168.Locked = False
    Else
    List168.Locked = True
    End If
    If Len(Project_Number & vbNullString) = 0 Then
    Projct_Number.Locked = False
    Else
    Project_Number.Locked = True
    End If
    End Sub

  12. #12
    scharj01 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2015
    Posts
    2
    Duh, I see the error. Projct.Number in the code typo! Fixed now. Works fine. Thanks

  13. #13
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Glad you found it, and welcome to the site.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 9
    Last Post: 09-13-2012, 05:18 PM
  2. activex control (ado data control)
    By metokushika in forum Access
    Replies: 4
    Last Post: 11-07-2011, 12:45 AM
  3. Form entry Control
    By Raury in forum Forms
    Replies: 1
    Last Post: 08-03-2011, 08:41 AM
  4. Replies: 4
    Last Post: 01-23-2011, 09:01 PM
  5. Data Entry And Data Recalling
    By GeeDee in forum Access
    Replies: 0
    Last Post: 05-01-2007, 05:20 AM

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