Results 1 to 9 of 9
  1. #1
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Morecambe England, Lancashire, England
    Posts
    105
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Locking fields on a form (Access 2000 / Windows 98)

    Hello again

    I

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Locking fields on a form (Access 2000 / Windows 98)

    You need code in two places: in the After Update event of the Position text box and in the On Current event of the form. Substitute the correct names in the following code:

    Private Sub Position_AfterUpdate()
    If Not IsNull(Me.Position) Then
    ' Position filled in, so clear Title and Initials
    Me.Title = Null
    Me.Initials = Null
    End If
    ' Set Enabled property
    Me.Title.Enabled = IsNull(Me.Position)
    Me.Initials.Enabled = IsNull(Me.Position)
    End Sub

    Private Sub Form_Current()
    ' Set Enabled property
    Me.Title.Enabled = IsNull(Me.Position)
    Me.Initials.Enabled = IsNull(Me.Position)
    End Sub

  3. #3
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Morecambe England, Lancashire, England
    Posts
    105
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Locking fields on a form (Access 2000 / Windows 98)

    Hi Hans,

    Thanks - worked perfectly

    The fact you used Enabled and I had talked about Locked though gave me a idea, so I tried Visible.

    So the code now looks like:-

    Private Sub Position_AfterUpdate()
    If Not IsNull(Me.Position) Then
    ' Position filled in, so clear Title and Initials
    Me.Title = Null
    Me.Initials = Null
    End If
    ' Set Visible property
    Me.Title.Visible = IsNull(Me.Position)
    Me.Initials.Visible = IsNull(Me.Position)
    End Sub

    Private Sub Form_Current()
    ' Set Visible property
    Me.Title.Visible = IsNull(Me.Position)
    Me.Initials.Visible = IsNull(Me.Position)
    End Sub

    So now there is no chance of a error as the boxes are not there!!

    Once again many thanks

    Michael

  4. #4
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Morecambe England, Lancashire, England
    Posts
    105
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Locking fields on a form (Access 2000 / Windows 98)

    Hi Hans again,

    I trying to get a bit smarter now and I

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Locking fields on a form (Access 2000 / Windows 98)

    I'm about to leave for dinner, so unless someone else replies, it'll have to wait until later tonight.

  6. #6
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Morecambe England, Lancashire, England
    Posts
    105
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Locking fields on a form (Access 2000 / Windows 98)

    Hans,

    No problems - Just makes me feel very bad as I've just finished mine!!

    Michael

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Locking fields on a form (Access 2000 / Windows 98)

    What? Your dinner was so bad that you've now got indigestion? <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Locking fields on a form (Access 2000 / Windows 98)

    Is the name of the control bound to Position also Position, or does it have a different name? Enabled is a property of the control, not of the field, so you should use the name of the control.

    If you type <code>Me.</code> somewhere in one of the procedures, IntelliSense will pop up a list of available properties and methods. Are Position and Contact among them?

  9. #9
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Morecambe England, Lancashire, England
    Posts
    105
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Locking fields on a form (Access 2000 / Windows 98)

    Dear Hans,

    Well now I Know the difference between a name and a field and I have learnt that the name postion is different to Field Position (with an i after the s) all is well

    The final code looks like this
    Private Sub Contact_BeforeUpdate(Cancel As Integer)
    If Not IsNull(Me.Contact) Then
    ' Contact filled in, so clear Title and Initials
    Me.Title = Null
    Me.Initials = Null
    End If
    ' Set Visible property
    'Visible if No Contact
    Me.Title.Visible = IsNull(Me.Contact)
    Me.Initials.Visible = IsNull(Me.Contact)
    'Invisible if no Contact
    Me.Position.Visible = Not IsNull(Me.Contact)

    End Sub

    Private Sub Form_Current()

    'Set Enabled property
    'Visible if no Contact
    Me.Title.Visible = IsNull(Me.Contact)
    Me.Initials.Visible = IsNull(Me.Contact)
    'Invisible if no Contact
    Me.Position.Visible = Not IsNull(Me.Contact)

    End Sub

    It all works perfectly I am now thinking about putting the position field over the top of the Title and Initials fields, but perhaps that a bit too clever.

    Thank you once more

    Michael

Posting Permissions

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