View Full Version : Text field autofill event not working


AndyEd08
10-13-2008, 12:08 AM
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...

maxmangion
10-13-2008, 12:29 AM
Hi,

try omitting the .Text part because unless the field has the focus it will return that error message you are receiving.

AndyEd08
10-13-2008, 12:35 AM
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....!?!

maxmangion
10-13-2008, 12:43 AM
Hi

Try renaming your form because according to this link (http://support.microsoft.com/kb/286335) "property" is a reserved word, so it might be conflicting.

AndyEd08
10-13-2008, 12:50 AM
Nope, that didn't work either....

Brianwarnock
10-13-2008, 01:00 AM
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

AndyEd08
10-13-2008, 01:11 AM
I've substituated that code but now I can tab onto the next field WITHOUT the "PropertyID" field updating??

Brianwarnock
10-13-2008, 02:52 AM
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

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

AndyEd08
10-13-2008, 04:13 AM
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.

gemma-the-husky
10-13-2008, 05:11 AM
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