Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Got Focus

Status
Not open for further replies.

sha123

Programmer
Nov 13, 2002
58
0
0
ZA
I have a form with a Field called RDRH and a field called area.

I want to add a value like "WC" in the area field till the value in the RDRH field = "RH" Then I want the area field to change to "Gau" is it possible to do it in the got focus option?

And how will I go about doing this with code builder?
 
Hi

Lets just be clear here,

You want the value of Area to be "WC", until the value of RDRH is "RH" at which point you want the value to become "Gau", right?

In the on Open Event of the form put

If RDRH = "RH" Then
Area = "WC"
Else
Area = "Gau"
End if

in the after update event of RDRH put the same eg

If RDRH = "RH" Then
Area = "WC"
Else
Area = "Gau"
End if

Putting the code in the lost focus event of RDRH would be OK, but would cuase code to be executed unnecessarily when tabbing off field if it had not changed



Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Thanks it it working up to a point!

It is putting "WC" in Area but as soon as it gets to the next RH field it continues to put "WC" in the field instead of going over to "Gau"!

I am maybe doing something wrong!!!

 
Hi

Do I detect that we are talking about a bound field in a recordset here?

If yes

If RDRH = "RH" Then
Area = "WC"
Else
Area = "Gau"
End if

in the oncurrent event

Danvlas's one line solution would work inplace of the If Then Else contruct, but if it is a bound field it would not allow the user to overtype it

Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Thanks Ken Reay And Danvlas

This is my code that I have been using, it works to some degree there is only one problem and it it that on the form
I have 10 Records with sub regions before we get to say the GAU region. Now I need all the other Records between the two regions to belong to the 1st regions Area?

Hope you understand:

Here is a sample:
RH GAU
RD JOH PO Box 111 Gau
RD POS PO Box 222

RD = Field "RDRH" and JOH = Field "Region" and Gau = Field "Area"
I now need the value in the area for the second record to become gau aswell.

RH = "Row Header"
RD = "Row Detail"

Private Sub Region_LostFocus()
If Region = "WC" Then
Area = "WC"
Else
If Region = "Gau" Then
Area = "Gau"
Else
If Region = "KZN" Then
Area = "Nat"
End If
End If
End If
End Sub
 
Hi

Ah, this is a different question -

If you are trying to update the table you should not be messing about in the form like this, use an Update query!

I do not know enough about your data to be sure, but it looks as if the easiest way would be to make a small table of Region and area, populate this table with a lsit of Regios for each area, then do a join on Region with your original table and update the Area column



Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top