IIf expression prob

G

Guest

i have a combo box field called type of employed whereby the user can select
either
-Company
- Self Employed(external)
- LSBU employed (Internal)

I have a course codes field, whereby i want to only allow a user to input
data into this field if they are LSBU employed(internal).
I have tried creating an Iif expression which i put in the control source of
my course codes text box

=IIf([Type of employment]="Company" Or "Self employed (External)","Not
Applicable","Please Press Browse Course")

which states that if the type of employment field is company or self
employed, it will insert 'Not Applicable'. If LSBU employed is selected from
the type of employment field, then it will insert the string "Please Press
Browse Course"

I would normally just lock the field in the properties section of that text
box, but i dont know how to do this if it is dependant on over values in the
form. Any methods?

Thanks
 
D

Dirk Goldgar

Connie said:
i have a combo box field called type of employed whereby the user can
select either
-Company
- Self Employed(external)
- LSBU employed (Internal)

I have a course codes field, whereby i want to only allow a user to
input data into this field if they are LSBU employed(internal).
I have tried creating an Iif expression which i put in the control
source of my course codes text box

=IIf([Type of employment]="Company" Or "Self employed (External)","Not
Applicable","Please Press Browse Course")

which states that if the type of employment field is company or self
employed, it will insert 'Not Applicable'. If LSBU employed is
selected from the type of employment field, then it will insert the
string "Please Press Browse Course"

I would normally just lock the field in the properties section of
that text box, but i dont know how to do this if it is dependant on
over values in the form. Any methods?

Thanks

This should work for the IIf() expression:

=IIf([Type of employment]
In ("Company", "Self employed (External)"),
"Not Applicable","Please Press Browse Course")

I had to break it onto multiple lines for the newsreader, but it would
really be one line.

But you should be aware that binding your text box to an expression like
this will make it uneditable. Was it your intention that the user
should enter something in this text box if [Type of employment] is "LSBU
employed (Internal)", and that otherwise the text box should be
disabled? If so, you shouldn't bind the text box to an expression. You
might use code in the form's Current event and in the AfterUpdate event
of [Type of employment] to set the text box's Enabled property.
Something like:

'----- start of example code -----
Private Sub EnableDisableCourseCodes()

Me!CourseCodes.Enabled = _
(Me![Type of employment] = "LSBU employed (Internal)")

End Sub


Private Sub Form_Current()

EnableDisableCourseCodes

End Sub


Private Sub Type_of_employment_AfterUpdate()

EnableDisableCourseCodes

End Sub
'----- end of example code -----

I don't know if that's exactly what you're after or not, but it rather
sounded like you want something like that.
 
G

Guest

I added this to the forms current event and i got an error message saying
"compile error: sub or function not defined?"

Private Sub Form_Current()
EnableDisable [Course Code]()

Form_Sw![Course Code].Enabled = _
(Form_Sw![Type of employment] = "LSBU employed (Internal)")
EnableDisable [Course Code]
End Sub

Dirk Goldgar said:
Connie said:
i have a combo box field called type of employed whereby the user can
select either
-Company
- Self Employed(external)
- LSBU employed (Internal)

I have a course codes field, whereby i want to only allow a user to
input data into this field if they are LSBU employed(internal).
I have tried creating an Iif expression which i put in the control
source of my course codes text box

=IIf([Type of employment]="Company" Or "Self employed (External)","Not
Applicable","Please Press Browse Course")

which states that if the type of employment field is company or self
employed, it will insert 'Not Applicable'. If LSBU employed is
selected from the type of employment field, then it will insert the
string "Please Press Browse Course"

I would normally just lock the field in the properties section of
that text box, but i dont know how to do this if it is dependant on
over values in the form. Any methods?

Thanks

This should work for the IIf() expression:

=IIf([Type of employment]
In ("Company", "Self employed (External)"),
"Not Applicable","Please Press Browse Course")

I had to break it onto multiple lines for the newsreader, but it would
really be one line.

But you should be aware that binding your text box to an expression like
this will make it uneditable. Was it your intention that the user
should enter something in this text box if [Type of employment] is "LSBU
employed (Internal)", and that otherwise the text box should be
disabled? If so, you shouldn't bind the text box to an expression. You
might use code in the form's Current event and in the AfterUpdate event
of [Type of employment] to set the text box's Enabled property.
Something like:

'----- start of example code -----
Private Sub EnableDisableCourseCodes()

Me!CourseCodes.Enabled = _
(Me![Type of employment] = "LSBU employed (Internal)")

End Sub


Private Sub Form_Current()

EnableDisableCourseCodes

End Sub


Private Sub Type_of_employment_AfterUpdate()

EnableDisableCourseCodes

End Sub
'----- end of example code -----

I don't know if that's exactly what you're after or not, but it rather
sounded like you want something like that.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
D

Dirk Goldgar

Connie said:
I added this to the forms current event and i got an error message
saying "compile error: sub or function not defined?"

Private Sub Form_Current()
EnableDisable [Course Code]()

Form_Sw![Course Code].Enabled = _
(Form_Sw![Type of employment] = "LSBU employed (Internal)")
EnableDisable [Course Code]
End Sub

That's not a whole lot like what I posted. I guess that "Course Code"
is the name of the text box to be enabled or disabled. Is that correct?
Also, I'm assuming that this code is all running in the code module of
the form that has the controls [Type of employment] and [Course Code].
If that's true, try this:

'----- start of revised code -----
Private Sub EnableDisableCourseCodes()

Me![Course Code].Enabled = _
(Me![Type of employment] = "LSBU employed (Internal)")

End Sub


Private Sub Form_Current()

EnableDisableCourseCodes

End Sub


Private Sub Type_of_employment_AfterUpdate()

EnableDisableCourseCodes

End Sub
'----- end of example code -----

Please note that there are three Subs there. It looks like you pasted
my original code all into the shell of the Form_Current Sub, which was
not the right way to do it. If you have no other code in the form's
module besides the code you tried to insert from my example, remove all
of that and paste this into the module's Declarations section, a line or
two below the "Option Compare Database" and "Option Explicit" lines.
(You may not have an "Option Explicit" line, depending on how you have
your VB options set).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top