If = Then Enable & Require

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

My from has a combo box lising company positions. Two of the ten positions
require a Managers Code.

If Position = "3" or "8" then require user to type the MangerCode into the
text box.

1- Where should the vba code go? After Update in the combo box?
2. How can I require the user to complete the required text field if he
selects # 3 or #8?
 
On the after update of your combo add
if me.Position = 3 or me.Position = 8 then
msgbox "Code require"
me.ManagersCode.setfocus
endif

On the before exit event of the ManagersCode
if isnull(ManagersCode) then
msgbox "Enter Code"
cancel=true ' will not let him exit the field, You need to concider that
because he can get into a loop.
endif

If you let him get out of the field then check on the form unload if the
combo equal 3 or 8 and the code is null, then give a message again.
 
The code below worked great. Now, let's stick another condition in.
- The employee can have more than one Manager Code so I put a subform onto
my main form so the user has the option of putting more than one Mgr ID #
into the Employee's Profile.

The subform's name is "MgrID subform" the relationship key between the two
forms are "EmployeeID"

How do I set focus onto the MgrID field in the subform so my user can insert
more than one Manager ID number?




Private Sub cboRoleID_AfterUpdate()
'
'If Me.cboPosition = "3" Or Me.cboPosition = "8" Then
'MsgBox ("You are required to type in this Employees Manager's ID#")
' Me.Mgr_ID.Enabled = True
'
'Me.Mgr_ID.SetFocus
'
' Else
' Me.InvOfficer_ID.Enabled = False
 
On your sub form properties you have child and father properties, its the
place where you link the two field father is employee field name from the
main table, child is the name of the employee field from the sub form managers

after you do that adding managers will link it auto to your employee
 
How do I set focus on the Mgr_ID in the subform from the main form?

'Me.Mgr_ID.SetFocus (???)
 
Forms![MainFormName]![SubFormName].Form!Mgr_ID

you can always use the builder to that for you
 
Back
Top