Results 1 to 3 of 3
  1. #1
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    Warrington, Cheshire, England
    Posts
    712
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have a main form with two sub-forms. Because of the way I am using the two sub-forms, I am forced to use datasheet view for both subforms.

    If the EmploymentType field on the main form (EmployeeDetail) records that the employee is permanent, I want to set the text colour for a field on the first sub-form to red, and lock the field; if temporary, the text colour has to be set back to black and the lock removed.

    I have written the following VB in the subform's Form_Current event routine :

    IF [Forms]![EmployeeDetail]![EmploymentType] = "Permanent" Then
    Me.[Hourlyrate].Forecolour = vbRed
    Me.[Hourlyrate].Locked = True
    Else
    Me.[Hourlyrate].Forecolour = vbBlack
    Me.[Hourlyrate].Locked = False
    End If

    The field is being locked and unlocked as required, but the colour is not changing.
    Can someone help with what I'm doing wrong, please?
    Thanks
    Silverback
    Silverback

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    The ForeColor property only applies to Form view, not to Datasheet view.
    In Datasheet view, you can only set the font color for the form as a whole, through the DatasheetForeColor property of the Form object. You can't set the font color of individual controls in datasheet view.
    You can, however, use Format | Conditional Formatting to set the font color of controls depending on a condition. This will work in both Form view and Datasheet view. You can refer to controls on another form when specifying the condition for conditional formatting (select Expression Is in the dropdown).

  3. #3
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    Warrington, Cheshire, England
    Posts
    712
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Amazing! I had a feeling it might be something to do with datasheet mode. I'd looked at Conditional Formatting but had not realised that Expression Is enabled reference to another form.
    Thanks so much, Hans.
    Silverback
    Silverback

Posting Permissions

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