Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2010
    Posts
    15

    Unanswered: locking field in form after new record

    I am trying to lock a field boxID and ContainerTypr(YRD) when the record isnt a new record. Here is my macro I wrote to try and do that: I am using access 2003

    Private Sub ConatinerForm(objForm As Form)

    BoxID = Form.NewRecord
    If BoxID = True Then
    objForm!BoxID.Locked = False
    objForm!ContainerType(YRD).Locked = False
    Else
    objForm!BoxID.Locked = True
    objForm!ContainerType(YRD).Locked = True
    End If

    End Sub

    Please help

  2. #2
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    For the record, that's VBA code, not a macro. Try this shot in the dark:

    If objForm.NewRecord = True Then
    Paul

  3. #3
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    By the way, where is that code? I noticed it's a Private Sub, but if you're trying to pass a form to it, it should be Public, and in a standard module.
    Paul

  4. #4
    Join Date
    Jan 2010
    Posts
    15

    nope

    Nope that didnt work thanks for trying though, I keep changing it up alittle and the trying the module name and the event procedure but it doesnt seem to let me change a new record in those fields

  5. #5
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Not sure why you cannot use some code in the form module: it seems to be the more logical place, but I imagine that you have your reasons. So, in the form module:
    Code:
    Private Sub Form_Current()
    
         LockControlsIfNewRecord Me
         
    End Sub
    And in an independant module:
    Code:
    Public Function LockControlsIfNewRecord(frm As Form)
    
        frm.ContainerType.Locked = frm.NewRecord
        frm.BoxID.Locked = frm.NewRecord
        
    End Function
    Of course it's easier if you can work in the form module:
    Code:
    Private Sub Form_Current()
    
        Me.ContainerType.Locked = Me.NewRecord
        Me.BoxID.Locked = Me.NewRecord
         
    End Sub
    Have a nice day!

  6. #6
    Join Date
    Jan 2010
    Posts
    15
    thanks for all of your help, I couldnt ever get it to work so I used this code and it worked,

    Private Sub Form_Current()
    If Nz(BoxID) = 0 Then
    BoxID.Locked = False
    Else
    BoxID.Locked = True
    End If
    End Sub

    Thanks again

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
  •