Brlang,
First point is that you do not seem to have declared the Lengthoffield variable. I would have expected to see something like this at the beginning of the procedure... Dim Lengthoffield As Integer
Second point is that the qry_key_definitions form needs to be open at the time when you are running this procedure. Is this the case?
-- Steve Schapel, Microsoft Access MVP
brlang[ at ]adelphia.net wrote:
[Quoted Text] > I have a box on a form that I am trying to validate the length of based > on a field in another form. I have tried using vb code but I get a > type match error or can not find the form if using the logic below. I > do not think that I have the right process in the code as I am new to > this. Code I have used in the beforeupdate is below: > > Private Sub key2_BeforeUpdate(Cancel As Integer) > > Lengthoffield = Len(Me.[key2]) > If Lengthoffield > Forms![qry_key definitions]![key_key2_len] Then > MsgBox "You have entered information that is too long for the > field." > Cancel = True > End If > End Sub >
|