Results 1 to 9 of 9
  1. #1
    Patience is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    May 2010
    Posts
    52

    Need code


    Hi guys!

    Can you please help me out with the code for this:

    I want a field in a form to be locked when existing records are displayed. However when a new record is being created/filled out in the form, then the field should be unlocked so the user can enter data into it.

    This is where I am:

    Code:
    Private Sub Item_number_BeforeUpdate(Cancel As Integer)
     
    Dim intNewRecord As Integer 
    intNewRecord = IsNull(Me![Item lot/piece number])
    If intNewRecord Then
     
     
    End Sub
    Thank you very much!

    BR

  2. #2
    Rawb is offline Expert
    Windows XP Access 2000
    Join Date
    Dec 2009
    Location
    Somewhere
    Posts
    875
    You're trying to assign a True/False value to a Numeric field.

    Try this:
    Code:
    Private Sub Item_number_BeforeUpdate(Cancel As Integer)
      If IsNull(Me![Item lot/piece number]) Then
        Me![Item lot/piece number].Locked = False
      Else
        Me![Item lot/piece number].Locked = True
      End If
    End Sub

  3. #3
    maximus's Avatar
    maximus is offline Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    I have a form and on the OnCurrent Event I put this code. This code locks the Skill Field if looking through exsisting entries and Unlocks when a new entry is opened.



    Private Sub Form_Current()
    If Me.NewRecord Then
    Me.Skill.Locked = False
    Else
    Me.Skill.Locked = True
    End If
    End Sub


    if this solves your problem mark the thread solved.

  4. #4
    Rawb is offline Expert
    Windows XP Access 2000
    Join Date
    Dec 2009
    Location
    Somewhere
    Posts
    875


    Oooo! Use Maximus' code instead!

    I didn't know about the .NewRecord property.

  5. #5
    Patience is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    May 2010
    Posts
    52
    Does not work guys. I get this error:

    Run-time error '438':

    Object doesn't support this property or method.

    It marks the .Locked part.

  6. #6
    Patience is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    May 2010
    Posts
    52
    It is not a numeric field. It is a text field. Don't know if that matters.

  7. #7
    maximus's Avatar
    maximus is offline Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    On which event did you put this code

  8. #8
    maximus's Avatar
    maximus is offline Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    paste your code that we can see

  9. #9
    Patience is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    May 2010
    Posts
    52
    UPS!

    It works. I just wrote the wrong field name - Sorry!

    Thanks a lot for the help.

    BR

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

Similar Threads

  1. Code help
    By Alex Motilal in forum Forms
    Replies: 3
    Last Post: 06-17-2010, 07:12 AM
  2. Help with code
    By steve183 in forum Programming
    Replies: 2
    Last Post: 06-04-2010, 05:14 PM
  3. Help with VBA code
    By bgonzal1 in forum Access
    Replies: 3
    Last Post: 12-14-2009, 07:12 AM
  4. Access 2003 code vs Access 2007 Code
    By ralphjramirez in forum Access
    Replies: 5
    Last Post: 11-23-2009, 12:33 PM
  5. Help with VBA Code
    By access.newby in forum Forms
    Replies: 1
    Last Post: 11-15-2009, 05:43 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