textbox value based on two other textboxs

bigmac

Registered User.
Local time
Today, 15:25
Joined
Oct 5, 2008
Messages
302
hi all, can you help please, I have three textboxes , textbox 1,textbox 2, and textbox 3, I can change the value of textbox 3 based on the date of textbox 2 by using
if me. textbox2 < date then
me. textbox 3 ="expired"
end if
but I need it to look at textbox 1 as well and only change textbox 3 to "expired" if both conditions are true. example
if textbox 1 = "abs" and
textbox 2 < date
then textbox 3 = "expired".
end if
how would I write this please:confused:
 
Hello,
Where is the problem? you write the code as you show :

Code:
If textbox 1 = "abs" and textbox 2 < date then 
textbox 3 = "expired"
End If

I hope it helps you. I suggest you to read some things about conditions in VBA
Good continuation
 
madefemere thanks works great how would I use this as an expression to put it on the textbox 3 as conditional formatting please?
 
You use the expression in the correspondant box

Code:
textbox 1 = "abs" and textbox 2 < date
 
You use the expression in the correspondant box

Code:
textbox 1 = "abs" and textbox 2 < date

Sorry if this is an 'OMG' question, but how does this conditional set textbox3 to "expired"? Is this code written in texbox3 control source in properties? :confused:
 
Hello and sorry, but it is not possible to assign valu to a control with the "contionnal formatting" process.
You must use events of controls like :
Code:
Private Sub Texte1_AfterUpdate()
If textbox 1 = "abs" and textbox 2 < date then 
     textbox 3 = "expired"
end If
End Sub
Or create a global module in the form like :
Code:
Private Sub UpDateTexte3()
If textbox 1 = "abs" and textbox 2 < date then 
     textbox 3 = "expired"
end If
End Sub
and you call it in the event of controls :
Code:
Private Sub Texte1_AfterUpdate()
UpDateTexte3
End Sub
Private Sub Texte2_AfterUpdate()
UpDateTexte3
End Sub
 
I see..... sort of. lol
In this case by using events, that means without some kind of action taken by the user
nothing happens? correct? maybe i am over thinking....

Never mind! I was too focused on text box events and wasnt thinking about the form itself....:banghead:
 
Last edited:
madefemere, is it possible to assign this so when ever the subform is updated/ refreshed that this automatically runs? if so how? please
 
Yes, you have an UpDate event in your subform where you can put the code.
 
No VBA is required for this task at all. It is easily achieved with a ControlSource for textbox3.

Code:
=IIf([text1]="abs" And [Text2]<Date(),"Expired",Null)
 

Users who are viewing this thread

Back
Top Bottom