Locking a Field in a Form in Form_Current()

  • Thread starter tudogman via AccessMonster.com
  • Start date
T

tudogman via AccessMonster.com

I’m relatively new to Access coding and I’m running just beyond the limits of
my knowledge.

I’ve got a shared Access 97 database with a module that returns the wrong
answer and/or locks the field that should not be locked.
The form is loaded from another form with the conditions set so that it will
display based on the Incident Number (incidentno).

Right now, I’ve got a MsgBox that will tell me the condition of the CheckBox
found in the DLookup when the form loads.
I can’t check the condition of the checkbox from the form as it is in a
different, password protected, form and not all users have access to.


Here’s the code:

Private Sub Form_Current()

'This subroutine will check the TBLincedent.Prelimorfinal field to see if it
is checked. If it is, it will
'lock the field so that a user cannot change the date.

'Set the initial definitions
Dim TargetComplete As Variant
Dim txtTargetComplete As String
Dim incidentno As Long
Dim txtincidentno As String
Dim TBLincident As Recordset
Dim Prelimorfinal As CheckBox
Dim inc As Variant 'Will determine the Incident Number
Dim chk As Variant 'Will be the result of combining TBLIncident &
Prelimorfinal

'find the Incident Number
inc = Forms![frmactionseditc].incidentno

'-----------------------------
' Do the DLookUp
chk = DLookup("[Prelimorfinal]", "TBLincident", "[txtTargetComplete]='" & _
Forms![frmactionseditc].[txtTargetComplete] & "'")

If chk = -1 Then
MsgBox "The box is " & chk & "!" & vbCrLf & " The Incident No is: " & inc,
vbOKOnly, "OK"
Me![txtTargetComplete].Locked = True
Me![txtTargetComplete].Enabled = False
Else
MsgBox "The box is " & chk & "!" & vbCrLf & "The Incident No is: " & inc,
vbOKOnly, "OK"
Me![txtTargetComplete].Enabled = True
Me![txtTargetComplete].Locked = False
End If

End Sub

What the HECK am I doing wrong!?
 
G

Guest

Try this one:

chk = DLookup("[Prelimorfinal]", "TBLincident", "[txtTargetComplete]= " & _
Forms![frmactionseditc].[txtTargetComplete])


Maurice
 
T

tudogman via AccessMonster.com

Maurice said:
Try this one:

chk = DLookup("[Prelimorfinal]", "TBLincident", "[txtTargetComplete]= " & _
Forms![frmactionseditc].[txtTargetComplete])

Maurice
I’m relatively new to Access coding and I’m running just beyond the limits of
my knowledge.
[quoted text clipped - 51 lines]
What the HECK am I doing wrong!?

Thanks for your help Maurice. Unfortunately, that returned an empty value.
The object of my DLookup was to return a value of either -1 or 0.
If the value returned was -1 it would lock the field txtTargetComplete in the
current form.
If the value returned was 0, it would Not lock the field in the current form.

When I call up the form for an Incident that has Not had the Prelimorfinal
field checked, I'm Still getting the value of -1.

I guess I should have been more descriptive in my original posting. I'll grab
myself by the collar and slap myself around for that for you.

Again thanks. If you see what I'm doing to get the value of -1 when the
value should be 0 I would be most grateful.
 
T

tudogman via AccessMonster.com

I figured it out!

This was a database that I had inherited. The DLookUp had to be run against
a query that the original author had created.

Who said that documentation is useless?

Thanks.
Try this one:
[quoted text clipped - 8 lines]
Thanks for your help Maurice. Unfortunately, that returned an empty value.
The object of my DLookup was to return a value of either -1 or 0.
If the value returned was -1 it would lock the field txtTargetComplete in the
current form.
If the value returned was 0, it would Not lock the field in the current form.

When I call up the form for an Incident that has Not had the Prelimorfinal
field checked, I'm Still getting the value of -1.

I guess I should have been more descriptive in my original posting. I'll grab
myself by the collar and slap myself around for that for you.

Again thanks. If you see what I'm doing to get the value of -1 when the
value should be 0 I would be most grateful.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top