VB code for checking if a field is not null (for locking a row) isneeded

  • Thread starter Thread starter raylopez99
  • Start date Start date
R

raylopez99

hi,

I need to automatically lock a field after it's been written into and
has lost focus. Right now I'm using a checkbox, but I want to lock
automatically once the field is dirtied (written into) and it loses
focus.

Actually I need to lock a row, but a field is a good start--I can
replicate the code for each field in a row I guess.

Any ideas?

RL

What I'm using now; it works, but you manually have to check a
checkbox, and I want to automate this:

If boolcheckbox = True Then

field001.Locked = True

Else
field001.Locked = False

End If
 
hi,

I need to automatically lock a field after it's been written into and
has lost focus. Right now I'm using a checkbox, but I want to lock
automatically once the field is dirtied (written into) and it loses
focus.

Actually I need to lock a row, but a field is a good start--I can
replicate the code for each field in a row I guess.

Any ideas?

RL

What I'm using now; it works, but you manually have to check a
checkbox, and I want to automate this:

If boolcheckbox = True Then

field001.Locked = True

Else
field001.Locked = False

End If

You could put your code into the Form_Current event, so that:

Me.SomeField.Locked = Me.chkCheckbox.True

..... this would lock a field if your checkbox is true. If you want to
make it generic, create a module with...

Public Function LockMyField (chk as Checkbox) as Boolean
LockMyField = chk.Value
End Function

.... and call the function from the Form_Current event. If you provide
a little more detail, I can give you more of my two cents.

-- James
 
You will need code in two places. One in the Lost Focus event of the text
box. (it is not a field, fields belong to tables and queries. On forms and
reports, they are controls).

If Not IsNull(Me.MyTextBox) Then
Me.MyTextBox.Locied = True
End If

And also in the Form current event to set it correctly for the record:


If Me.NewRecord Then
Me.MyTextBox.Locked = False
ElseIf IsNull(Me.MyTextBox) Then
Me.MyTextBox.Locked = False
Else
Me.MyTextBox.Locked = True
End If
 
You will need code in two places.  One in the Lost Focus event of the text
box. (it is not a field, fields belong to tables and queries.  On forms and
reports, they are controls).

Yes, thanks, this worked Klatuu. Milton M's solution wasn't as
intuitive to me so I didn't try it (though I have figured out that VB
likes to cast stuff using the "As" keyword and that "me" is what C#/C+
+ calls the 'this' pointer).

Access forms using VB is great for rapidcoding...

RL
 
Back
Top