Textbox only allowing input when another textbox is not Null

lovett10

Registered User.
Local time
Today, 12:15
Joined
Dec 1, 2011
Messages
150
I have 3 texboxes

Engineer 1

Engineer 2

Engineer 3

and would like the user to not be able to enter into Engineer 2 until Engineer 1 has been filled.

likewise engineer 3 shouldnt be able to be filled untill engineer 1 and 2 are filled.


I would like this to be achieved either with the boxes being greyed out or just a messagebox when you try and type in them.

Thanks for any help

P.s access 2010
 
Suggestion, on the AfterUpdate event of the Engineer 1 control, check the control's value and decide if other control(s) should be enabled / disabled.

When coding up the AfterUpdate event, you need to get the field's value via the .Text property, not the .Value property that works other times.
 
Suggestion, on the AfterUpdate event of the Engineer 1 control, check the control's value and decide if other control(s) should be enabled / disabled.

When coding up the AfterUpdate event, you need to get the field's value via the .Text property, not the .Value property that works other times.


Hi thanks for the suggestion, but i dont want it to say..not allowed after they try and save. i just want to make it so they cant put it wrong in the first place.


Thanks for the help
 
I think you will also need the code suggested by mdlueck in the form's On Current event.
 
Like Michael (aka mdlueck mentioned), use the After Update event of each textbox. So as an example, the following will go in the After Update event of Engineer 2
Code:
If Len(Me.Engineer1 & vbNullString) = 0 Then
    Cancel = True
    Msgbox "Engineer 1 must be filled in ..."
End If
NB: It's the Value property you need. That's an optional property as seen in the code.
 
ok heres what ive got

If Me.Engineer 1 & "" <> "" Then
Engineer 2.Text = Disable

I realize this is not correct and i dont know a lot im just guessing tbh

Thanks for the help guys
 
Like Michael (aka mdlueck mentioned), use the After Update event of each textbox. So as an example, the following will go in the After Update event of Engineer 2
Code:
If Len(Me.Engineer1 & vbNullString) = 0 Then
    Cancel = True
    Msgbox "Engineer 1 must be filled in ..."
End If
NB: It's the Value property you need. That's an optional property as seen in the code.

This gives me a syntax errror
 
The syntax error is coming from your end. Look at your code again and compare it to mine.
 
i dont want it to say..not allowed after they try and save. i just want to make it so they cant put it wrong in the first place.

And I was off thinking nasty thoughts of:

1) Fill in Engineer 1
2) Fill in Engineer 2
3) Blank out Engineer 1
4) Commit the changes

:D

Looks like you are getting good peer suggestions. This is a really great group of people to learn from.
 
The syntax error is coming from your end. Look at your code again and compare it to mine.

Private Sub Engineer_2_AfterUpdate()
If Len(Me.Engineer 1 & vbNullString) = 0 Then
Cancel = True
MsgBox "Engineer 1 must be filled in ..."
End If
End Sub

the box is called Engineer 1 not Engineer1 do i need a _?
 
Oh, and you could do all of this validation checking in a pre-commit area of code within the commit button.

I do not validate forms until the record is attempted to be committed.

Validation code reads the form controls (harvests data from the controls), checks it over, then if any field is found to be of improper value the validation code turns the field red and the event ends.

If the field was found to be good, the validation code changes the background to white (should always set the color as people could be playing games trying to hack the validation code). If all fields were found to be good, then the data is transferred from the Validation class to the DB class, and the appropriate DB operation is called (INSERT / UPDATE / etc..)

So, I find it very hard to build validation logic into the controls themselves, prefer instead to have validation tied to the commit button. "Leave the user alone while they make changes... check up on what they did when they click Commit" is the direction I err towards.
 
NB: It's the Value property you need. That's an optional property as seen in the code.

hhhmmm... The one place I remember coding to AfterUpdate.... Oh, that was on the Change event I remembered having to grab the value out of Nz(Me.fldFind.Text, "") to support a "search as you type" capability.

My bad... the AfterUpdate place was on the ONE Multiple Records form I allowed users to make updates on, and the AfterUpdate code was to force the change back into the FE DB temp table RIGHT away. (Reminds me why I insist on having Multiple Records forms be READ ONLY!!!)
 
hhhmmm... The one place I remember coding to AfterUpdate.... Oh, that was on the Change event I remembered having to grab the value out of Nz(Me.fldFind.Text, "") to support a "search as you type" capability.
That's the one mdlueck. You use the Text property when the control has focus and when you want to validate every keystroke, in which case the Change event is used.
 
The code hasn't changed! Same as before. mdlueck was just explaining other validation methods.
 
The code hasn't changed! Same as before. mdlueck was just explaining other validation methods.

Im getting this:

The expression On Load you entered as the even property setting produced the following error: Procedure decleration does not match the description of event of procedure hacving the same name.

*The expression may not result in the name od a macro, the name of a user defined function, or Event Procedure
*There may have been an error evaluation the function, event or macro
 
You've change the Load event signature of your form. Upload it and I'll have a look.
 

Users who are viewing this thread

Back
Top Bottom