Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms / May 2007

Tip: Looking for answers? Try searching our database.

Locking a Field in a Form in Form_Current()

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
tudogman - 03 May 2007 18:57 GMT
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!?
Maurice - 03 May 2007 21:23 GMT
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!?
tudogman - 04 May 2007 17:39 GMT
>Try this one:
>
[quoted text clipped - 8 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.
tudogman - 07 May 2007 15:44 GMT
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 - 16 lines]
>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.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.