Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / April 2005

Tip: Looking for answers? Try searching our database.

IIf expression prob

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Connie - 05 Apr 2005 02:17 GMT
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
Dirk Goldgar - 05 Apr 2005 02:31 GMT
> i have a combo box field called type of employed whereby the user can
> select either
[quoted text clipped - 20 lines]
>
> 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.

Signature

Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

Connie - 05 Apr 2005 04:19 GMT
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

> > i have a combo box field called type of employed whereby the user can
> > select either
[quoted text clipped - 62 lines]
> 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 - 05 Apr 2005 04:42 GMT
> I added this to the forms current event and i got an error message
> saying "compile error: sub or function not defined?"
[quoted text clipped - 6 lines]
>     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).

Signature

Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.