need VB code to enable next field once the first textbox has been updated

tafnuef1

Registered User.
Local time
Today, 03:46
Joined
Apr 22, 2010
Messages
43
Ok here goes. I love my Access form and it is working great. But My VB coding experience is horrible. I would like my Form to now be set up where I can ensure the Batch Number ID is entered for the form first (which is the first textbox for the user to fill in). Actually I want the Batch Number ID, Document Count and Date of Audit all filled out before the user can progress into the form. I would like everything greyed out then once the "required fields" are completed the rest are activated. Is that possible?

So what code do I use? Do I start by placing and "event Procedure in the BeforeUpdate? Or OnClick? Once I figure out where to place it what code do you suggest.

HELP I am so close to sending this out for testing before we send it to the users to start entering data. So exciting.
 
I would imaging you'd call a custom function from the after-update event of the controls that you require to be filled out that would first check to see if all required fields have been completed, and then enable of disable the secondary fields depending on the result. Bear in mind that you'll likely need to call the function from the on_current event of the form so that when the user changes records the secondary fields are disabled.

Maybe somehting like (air code)

Code:
Public function ValidateField()
Dim varValidated as Boolean 'flags whether all required fields contain data or not
Dim ctl As Control

varValidated = True 'start assuming all required fields contain data

For Each ctl In Me.Controls
    If (ctl.Tag = "Required" )Then
        'if any required field is empty change the flag to false
        If ctl.Value & "" = "" Then varValidated = False     
End If
Next ctl

If varValidated Then 
'all required controls contain data so enable secondary field controls
    For Each ctl In Me.Controls
        If (ctl.Tag = "Secondary" )Then ctl.Enabled = True
    Next ctl
Else 
'all required controls do not contain data so disable secondary field controls
    For Each ctl In Me.Controls
        If (ctl.Tag = "Secondary" )Then ctl.Enabled = False
    Next ctl
End If
End Function

To make this work, you would need to set the Tag property of each of the required fields to 'Required' and the Tag value for the fields that you want to enable/disable to 'Secondary' (no quotes required btw).

Then, call the function from the after_update event of each of the required fields and the on_current event of the form.
Code:
Private Sub SomeControl_AfterUpdate() 
Call ValidateField()
End Sub

HTH
 

Users who are viewing this thread

Back
Top Bottom