Text field autofill event not working

AndyEd08

New member
Local time
Today, 10:16
Joined
Oct 10, 2008
Messages
6
I have inputted the following code as an "After Event" sequence on a form which should cause a field entitled "PropertyID" to be filled with a string comprising of elements from 2 other user inputted fields.

It is not working however, displaying the following message:

"Run-time error '438'
Object doesn't support this property or method", with de-bugger focussing in on the line shown below with the arrow.

Code is:

Private Sub Postcode_AfterUpdate()

Dim adl1 As String
Dim pcode As String
Dim pid As String

pcode = Forms!Property!Postcode.Text

Forms!Property!AddressLine1.SetFocus
adl1 = Forms!Property!AddressLine1.Text

pid = UCase(Right(pcode, 3) & Left(adl1, 2))

If Len(pid) = 5 Then
Forms!Property!PropertyID.SetFocus <---

If Forms!Property!PropertyID = "" Then
Forms!Property!PropertyID = pid

End If
End If

Forms!Property!Picture.SetFocus
End Sub

Anyone got any suggestions??? I've tried allsorts...
 
Hi,

try omitting the .Text part because unless the field has the focus it will return that error message you are receiving.
 
Hi thanks for the response. I'm a complete newcomer to this...so it's doubly frustrating although brilliant when it goes right.

I've omitted the .Text references but the same happens....!?!
 
Hi

Try renaming your form because according to this link "property" is a reserved word, so it might be conflicting.
 
Why do you keep Setting focus?

I think that you should code

If Len(pid) = 5 And Me.PropertyID = "" Then
Me.PropertyID = pid
End If

I have assumed that the active form is Property


Brian
 
I've substituated that code but now I can tab onto the next field WITHOUT the "PropertyID" field updating??
 
I can't see that anything that you were attempting to do would do that, however if your requirement is to prevent the record being saved with nothing in the propertyid then the place to do that is in the FORMS BEFORE UPDATE event

Then

Code:
If Me.PropertyID = "" or Me.PropertyID = " " Then
Me.PropertyID = UCase(Right(me.pcode, 3) & Left(Me.AddressLine1,2))
End if

Is all you need

Brian
 
It's still not working, although I can sense that this should be so straightforward...Perhaps if I define the setup...

I have a series of fields within a tabbed control, each holding information about a property. I would like to set the ID field up using the last 3 digits from the "Postcode" field and the first 2 digits from the "AddressLine1" field.

That's it!!

In case it makes a difference: the postcode field has an input mask applied to format how it appears & there is an "after update" expression set on the AddressLine1 field to display words in PROPER case.
 
you dont need to select the fields etc

surely just

id = left(addressline1,2)&right(postcode,3) should do it

however, you will get issues possibly if addressline1 or postcode are blank/null, which you may need ot deal with
 

Users who are viewing this thread

Back
Top Bottom