On Lost Focus error

edkocol

Registered User.
Local time
Today, 07:57
Joined
Oct 2, 2012
Messages
30
I am working on a system I did not develop in Access 2010. A form (that was called by another form) generates an error when moving from any field that contains an On Lost Focus event.

The Access error message is: The expression On Lost Focus you entered as the event property setting produced the following error: User-Defined type not defined.

Here is the Private Sub FistName_LostFocus() code from one such field:
Code:
Private Sub FirstName_LostFocus()
If IsNull(Me!FirstName) Then
    MsgBox "Must enter First Name"
    Me!LastName.SetFocus
    Me!FirstName.SetFocus
Else
   Me!FirstName.Value = StrConv(Me!FirstName, vbProperCase)
End If
End Sub

Reading elsewhere it seems that the desired method is to use BeforeUpdate/AfterUpdate. When I move the above code to a BeforeUpdate event and I leave the First Name blank I do not receive the message "Must enter First Name" but I receive an Access error: The expression Before Update you entered as the event property setting produced the following error: User-Defined type not defined.

Can anyone tell me

a) what is wrong with this code
b) what is the desired approach to edit checks of this nature

TIA for any help you can give.
 
Last edited:
Well, for one, you have FistName and not FirstName as the name of your control.
Private Sub FistName_LostFocus()

EDIT: So, what that means is you are using Me!FirstName.SetFocus but since there is no control named that, the bang then makes it refer to the field name (if the control isn't named the same) and the field has no such property or method.
 
Last edited:
Well, for one, you have FistName and not FirstName as the name of your control.
Private Sub FistName_LostFocus()

Sorry, typo. Was manually typing that line....:banghead:
 
Well, for one, you have FistName and not FirstName as the name of your control.
Private Sub FistName_LostFocus()

EDIT: So, what that means is you are using Me!FirstName.SetFocus but since there is no control named that, the bang then makes it refer to the field name (if the control isn't named the same) and the field has no such property or method.

EDIT: See above. The "Private Sub.." line in the post was manually typed and I made a mistake.
 
You'd better double check all of the control names as I mentioned in my edit above.

I did. Again, only in the OP did I make a typo on the Sub name. I realized that I had copied in the code without the "Private Sub...." line and so I manually typed that name in the OP.

In the form it is First;)
 
Try changing to the dot instead:

Code:
Private Sub FirstName_LostFocus()
If IsNull(Me.FirstName) Then
    MsgBox "Must enter First Name"
    Me.LastName.SetFocus
    Me.FirstName.SetFocus
Else
   Me.FirstName.Value = StrConv(Me.FirstName, vbProperCase)
End If
End Sub
 
Try changing to the dot instead:

Code:
Private Sub FirstName_LostFocus()
If IsNull(Me.FirstName) Then
    MsgBox "Must enter First Name"
    Me.LastName.SetFocus
    Me.FirstName.SetFocus
Else
   Me.FirstName.Value = StrConv(Me.FirstName, vbProperCase)
End If
End Sub

I tried that. No change.
 
Try commenting out each line one by one - run it, comment out, run, comment out and so on until the error goes away. That last commented out line will be what we need to focus on. Can you upload a copy of the DB so we can look?
 
The error never went away even with all lines commented out.

How would I upload a non-public copy of the db to you? zipped up it's 125mb.

I would display a copy of the properties for the field but I need a 10 posts before I can do that.
 
The error never went away even with all lines commented out.

How would I upload a non-public copy of the db to you? zipped up it's 125mb.

I would display a copy of the properties for the field but I need a 10 posts before I can do that.
Did you run Compact and Repair before zipping?

You could email a copy to me and I can take a look when I get home. If you want to do that instead, I'll PM you an email address to use.
 
After a compact & repair the zipped size is now 103mb. And the error still occurs FWIW.

Please PM me an email address to use.
 
Ed:

You’re going to crack up when I tell you why this was happening. It took me a few minutes but it didn’t take long to track it down. But it was necessary to have the database to do the investigation. It turns out that by going to the VBA window and to DEBUG > PROJECT it took me right to the offending line. The thing is, is that it has nothing to do with the lost focus events. It is the declaration of a Word object without having a reference to Word set. Sometimes the errors don’t really relay the correct information. So, after adding in the reference to Word, it works fine.

Bob

Oh, yeah and I’ve deleted the files and emptied my recycle bin.
 

Users who are viewing this thread

Back
Top Bottom