text box troubles

mattbland

Isnt really listening
Local time
Today, 03:35
Joined
Aug 8, 2002
Messages
33
Hey,
This probably sounds really stupid but im tryin to get a line of text into a text box once a condition has been met, but so far to no avail! this is the code im using:

Private Sub Status_GotFocus()

If Val(Min_stock > Act_stock) Then
Status.Text = "Urgent - Below Minimum Stock"
Else
Status.text=""
End If

End Sub

Help! this is doing my head in!
 
Personally I would use a label.

Then OnCurrent of the form put

If Me.Min_Stock > Me.Act_Stock Then

Me.LabelName.Caption = "Urgent stock needed"

else

Me.LabelName.Caption = ""

End If

or you could type in the words and then switch the visible property on or off as required by the If statement.

Hope this helps

Col
 
sorry, i am an idiot, OnCurent? is this an event property coz its not on the list.

ta for the help tho!
 
On Current is a property of the form itself, not the label or textBox.

If you use that then the code will run every time you go to a next or previous record. That way your InStock or OutofStock will be recalculated.

Col
 
well, i thought it did anyway, sorry!

couldnt find OnCurrent so i used Current (same i thought) but the table only updates when you move to the next page, and i need it to update straightaway. Also, with using the labels im not getting an entry into the original table, which i need so i can create a query, and then a report both based on the status fields. Any ideas??
 
Ok - two things here

1) Put the code in the OnOpen event of the form as well as the OnCurrent, that way it will calculate when the form opens and will give you a result for the first record the form opens to. It will recalculate as you scroll though as well.

2) It not a really good idea to have the result of a calculated field entered into the table, one of the reasons being that the result changes and it wastes space.
Do the calculation in a query using an IIf statement. Like this - lets say you have these fields in a query

ItemName
ActStock
MinStock

Add a new field like this

Status: IIf([MinStock]>[ActStock],"Stock Needed","Stock OK")

When you run the query the new field called status will contain the appropriate message. You can then run the report from the query as normal.

Hope I've helped
Col
 
thanks again col but it doesnt matter if the results change in the table, coz the report is goin to display those items which are out of stock at a partiular time (whenever updated)
 
got the query bit down, but where does the iif statement go?:confused:
 
In the query grid - instead of selecting an existing field, you create a calculated one. So where you have the fieldName - type this

Status: IIf([MinStock]>[ActStock],"Stock Needed","Stock OK")
 
u r a very understanding patient star of a man. i thank u!!:D
 

Users who are viewing this thread

Back
Top Bottom