Re: Visible/Invisible textboxes on a form - done by record
- From: Steve Schapel <schapel@xxxxxxxxxxx>
- Date: Tue, 12 Jul 2005 06:39:37 +1200
Pele,
I can't immediately see what might be causing the error. There are, however, some problems with the code. In your earlier posts you referred to [Labor Rate Code]. Is this actually called [labor_type_cd]? With the _s in the field name? Ok, as for the controls that you are trying to hide or otherwise, I would put a ! instead of a . if you are using the []s. If you type Me. in the VB editor, and then the first letter of the control, the 'Intellisense' should find it for you. If there is a space in the field name, it is automatically replaced by a _ so you would get Me.Monthly_rate etc. Try it like that, or else Me![Monthly rate].
Also, you need to be setting Enabled to Yes and Locked to No, or Enbled to No and Locked to Yes. So for each control, the code for the enabled and locked properties is opposite. But note also that...
([labor_type_cd] <> 2 Or [labor_type_cd] <> 7)
.... isn't correct, this will always evaluate to True. You need And instead of Or.
So, try tidying it up, something along these lines... Me.Hourly_rate.Locked = (Me.labor_type_cd = 2 Or Me.labor_type_cd = 7) Me.Hourly_rate.Enabled = (Me.labor_type_cd <> 2 And Me.labor_type_cd <> 7) ... etc.
If you still get the error, try removing (commenting out) some of the code, so the Enabled and Locked toggling only applies to one of the fields (just to simplify it for troubleshooting purposes).
-- Steve Schapel, Microsoft Access MVP
Pele wrote:
Steve,
I am assuming that the conditional formatting will not help.
Anyway, I did your initial recommendation and I am getting a runtime error 2465 "Microsoft Access can't find the field forms referred to in your expression"
Below is the code I wrote. Note that I have enclosed my text box names in parenthesis since the names have spaces in them.
Private Sub Form_Current() 'prevent data entry into hourly rate, Vacation weeks and Other Weeks Me.[hourly rate].Locked = ([labor_type_cd] = 2 Or [labor_type_cd] = 7) Me.[Vacation weeks].Locked = ([labor_type_cd] = 2 Or [labor_type_cd] = 7) Me.[Other weeks].Locked = ([labor_type_cd] = 2 Or [labor_type_cd] = 7) Me.[Monthly rate].Enabled = ([labor_type_cd] = 2 Or [labor_type_cd] = 7) 'prevent data entry into Monthly Rate Me.[hourly rate].Enabled = ([labor_type_cd] <> 2 Or [labor_type_cd] <> 7) Me.[Vacation weeks].Enabled = ([labor_type_cd] <> 2 Or [labor_type_cd] <> 7) Me.[Other weeks].Enabled = ([labor_type_cd] <> 2 Or [labor_type_cd] <> 7) Me.[Monthly rate].Locked = ([labor_type_cd] <> 2 Or [labor_type_cd] <> 7) 'prevent data entry to following fields if Manpower employee Me.[Vacation weeks].Locked = ([labor_type_cd] = 5) Me.[Other weeks].Locked = ([labor_type_cd] = 5) Me.[Monthly rate].Locked = ([labor_type_cd] = 5) End Sub
.
- References:
- Visible/Invisible textboxes on a form - done by record
- From: Pele
- Re: Visible/Invisible textboxes on a form - done by record
- From: Steve Schapel
- Re: Visible/Invisible textboxes on a form - done by record
- From: Pele
- Re: Visible/Invisible textboxes on a form - done by record
- From: Steve Schapel
- Re: Visible/Invisible textboxes on a form - done by record
- From: Pele
- Re: Visible/Invisible textboxes on a form - done by record
- From: Steve Schapel
- Re: Visible/Invisible textboxes on a form - done by record
- From: SteveS
- Re: Visible/Invisible textboxes on a form - done by record
- From: Steve Schapel
- Re: Visible/Invisible textboxes on a form - done by record
- From: SteveS
- Re: Visible/Invisible textboxes on a form - done by record
- From: Pele
- Visible/Invisible textboxes on a form - done by record
- Prev by Date: RE: How do I filter a data*** using VBA?
- Next by Date: RE: Changing field based on size
- Previous by thread: Re: Visible/Invisible textboxes on a form - done by record
- Next by thread: Re: Visible/Invisible textboxes on a form - done by record
- Index(es):