Enabling Certain Controls (1 Viewer)

MajP

You've got your good things, and you've got mine.
Local time
Today, 13:38
Joined
May 21, 2018
Messages
8,527
I think you need additional code to unlock the controls once the required fields are entered. That is why I suggest removing the message from the validation function. This why you can call the function on the after update of each required field. I would make the check generic so you can call it from many places such as the on current or the after update of the required controls.

Code:
Private Sub enableDisable()
   'ValidationOfControl = True when certain fields are not populated
   'When F_Project is opened with this button, these fields should have already been populated.
   Dim valid As Boolean
   valid = ValidationOfControl(Me)
     With Me
        .cboProjectFY.Enabled = Not valid
        .cboProjectType.Enabled = Not valid
        .cboFundingType.Enabled = Not valid
        .CheckPSD.Enabled = Not valid
        .CheckNEPA.Enabled = Not valid
        .CheckActive.Enabled = Not valid
        .CheckActiveAwarded.Enabled = Not valid
        .CheckActiveContractor.Enabled = Not valid
        .CheckCloseOutProject.Enabled = Not valid
        .txtEstimate.Enabled = Not valid
        .txtProjectPriority.Enabled = Not valid
        .txtDateCreated.Enabled = Not valid
        .SF_Contract.Enabled = Not valid
        .TabCtProjects.Enabled = Not valid
     End With
End Sub
 

Weekleyba

Registered User.
Local time
Today, 12:38
Joined
Oct 10, 2013
Messages
586
Ok, I think I'm following....
For the Public Function I widdled it down to,

Code:
Public Function ValidationOfControl(frm As Access.Form) As Boolean
'This function requires the user to provide data to Combo and Text boxes that have a * in the Tag property.
    Dim nl As String, ctl As Control
    Dim boolResult As Boolean
    
    nl = vbNewLine & vbNewLine
    For Each ctl In frm.Controls
        If ctl.ControlType = acComboBox Or ctl.ControlType = acTextBox Then
            If ctl.Tag = "*" And Len(ctl.Value & "") = 0 Then
              ctl.SetFocus
              boolResult = True
              Exit For
            End If
        End If
        Next ctl
ValidationOfControl = boolResult
End Function

Then for the BeforeUpdate event of the Project form I put,

Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
'ValidationOfControl can be True or False.
'False - all tagged fields have data
'True - one or more tagged fields have missing data
 
Cancel = ValidationOfControl(Me)
  If ValidationOfControl(Me) = True Then
  MsgBox "You need to fill in the require info first!"
  End If
  
End Sub

The problem is I get a 3021 error code now when I press the ButtonCloseProject_F.
Any idea how to get rid of that?
 

vba_php

Forum Troll
Local time
Today, 12:38
Joined
Oct 6, 2019
Messages
2,880
weekley,

the error is a "no current record" error. are you sure you have your db setup properly so it can take on all the advice you've gotten here? I'm thinking there's a slight chance that everything you've implemented so far from the advice that's been given has resulted in the unexpected errors you're now seeing because not enough info was given to begin with or not enough contingency was put in place before trying to advise on the original problem. I might be wrong. I'm wrong quite often as it is. do you wanna post the actual db file you're working with so people can make sure that's not what's happening?
 

Weekleyba

Registered User.
Local time
Today, 12:38
Joined
Oct 10, 2013
Messages
586
I've tried a couple more things and manage to eliminate the error code although I did it by eliminating the error checking stuff and placed a 'On Error Resume Next' on the ButtonCloseProjectF.
I'm not at all familiar with error checking code.....yet.

My solution is a bit clumsy as it requires clicking the close button twice on the project form.... not sure why??

Please take a look at the uploaded database and let me know what I need to improved upon.

Thanks!
 

Attachments

  • 0 DFM 4.zip
    461.8 KB · Views: 95

isladogs

MVP / VIP
Local time
Today, 18:38
Joined
Jan 14, 2017
Messages
18,211
I guess I don't follow Isladogs.
They are already disabled by default (as I understand it)
I have the Enable set to No for each combo box or text box on the Project form that
I do not want the user to enter data in, until the certain combo boxes and text
boxes are first filled in. That is was the ValidationOfControls does for me.

Is that what you are saying?

Hi
I've only just had time to look at your database and had various comments written but found these had already been made by MajP.

Removing If me.dirty =false fixed the issue with controls being enabled at form load
The messages are confusing and in one case it appears before the form is loaded. Add code to enable each control in turn or all at once to prevent further error messages. That should also solve error 3021

I would investigate the use of the Tag property as already mentioned

Also although you've ticked Require variable declaration (good!), that doesn't retrospectively alter existing code modules. Each code module should have Option Explicit as the second line. Add that then fix any compile errors arising.

Anyway, I'll bow out and leave you in the capable hands of MajP
 

Users who are viewing this thread

Top Bottom