Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access thread: Locking a record in access


Message #1 by njfarrell@h... on Tue, 26 Feb 2002 14:48:20
I want to lock a record in access depending on whether one of its own 

field values says yes or no.

I wrote a module which runs as a macro behind the next,previous etc 

buttons. It works well except for the last record. For some reason it 

won't see what value is in field for this record.when your clicking the 

next button it workas fine till here. It won't work either for the find 

button. Heres the code any suggestions would be appreciated. Oh yeah this 

locks the form rather then the record

Function Locks()

On Error GoTo Locks_Err

    

    Dim lngrecordnum

    Dim dbMyDB As Database

    Dim rsMyRS As Recordset

    Set dbMyDB = OpenDatabase("DuraporeComplaintsDatabase2001.mdb")  

    Set rsMyRS = dbMyDB.OpenRecordset("Complaints Table", dbOpenDynaset)

    rsMyRS.MoveFirst    'Move to first record

    

    lngrecordnum = Forms!

frmNotificationofComplaint.CurrentRecord               'find current 

record on form

    

    rsMyRS.Move lngrecordnum - 1        'move to record 

      

    If rsMyRS!Notification_approval = "True" Then

        Forms!frmNotificationofComplaint.AllowAdditions = False

        Forms!frmNotificationofComplaint.AllowDeletions = False

        Forms!frmNotificationofComplaint.AllowEdits = False

    Else

        Forms!frmNotificationofComplaint.AllowAdditions = True

        Forms!frmNotificationofComplaint.AllowDeletions = True

        Forms!frmNotificationofComplaint.AllowEdits = True

    End If

    

 Locks_Exit:

    Exit Function

    

Locks_Err:

    Resume Locks_Exit

End Function

Message #2 by "John Ruff" <papparuff@c...> on Tue, 26 Feb 2002 06:58:51 -0800
This is a multi-part message in MIME format.



------=_NextPart_000_000D_01C1BE93.0CA3B5D0

Content-Type: text/plain;

	charset="us-ascii"

Content-Transfer-Encoding: 7bit



I have modified your code.  You want to place the modified code in the

Form's module and then call the module from the form's On Current event

and on the Notification_Approval After Update event.  This will resolve

your issue.



Private Sub Locks()

On Error GoTo Locks_Err



    if Notification_Approval then

          .AllowAdditions=False

        .AllowDeletions = False

        .AllowEdits = False

    Else

        .AllowAdditions = True

        .AllowDeletions = True

        .AllowEdits = True

    End If

   

Locks_Exit:

    Exit Function

   

Locks_Err:

    Resume Locks_Exit

End Sub







John Ruff - The Eternal Optimist J



Always looking for Contract Opportunities



 



9306 Farwest Dr SW



Lakewood, WA 98498



papparuff@c...







-----Original Message-----

From: njfarrell@h... [mailto:njfarrell@h...]

Sent: Tuesday, February 26, 2002 2:48 PM

To: Access

Subject: [access] Locking a record in access





I want to lock a record in access depending on whether one of its own

field values says yes or no.

I wrote a module which runs as a macro behind the next,previous etc

buttons. It works well except for the last record. For some reason it

won't see what value is in field for this record.when your clicking the

next button it workas fine till here. It won't work either for the find

button. Heres the code any suggestions would be appreciated. Oh yeah

this

locks the form rather then the record

Function Locks()

On Error GoTo Locks_Err

   

    Dim lngrecordnum

    Dim dbMyDB As Database

    Dim rsMyRS As Recordset

    Set dbMyDB = OpenDatabase("DuraporeComplaintsDatabase2001.mdb") 

    Set rsMyRS = dbMyDB.OpenRecordset("Complaints Table", dbOpenDynaset)

    rsMyRS.MoveFirst    'Move to first record

   

    lngrecordnum = Forms!

frmNotificationofComplaint.CurrentRecord               'find current

record on form

   

    rsMyRS.Move lngrecordnum - 1        'move to record

     

    If rsMyRS!Notification_approval = "True" Then

        Forms!frmNotificationofComplaint.AllowAdditions = False

        Forms!frmNotificationofComplaint.AllowDeletions = False

        Forms!frmNotificationofComplaint.AllowEdits = False

    Else

        Forms!frmNotificationofComplaint.AllowAdditions = True

        Forms!frmNotificationofComplaint.AllowDeletions = True

        Forms!frmNotificationofComplaint.AllowEdits = True

    End If

   

 Locks_Exit:

    Exit Function

   

Locks_Err:

    Resume Locks_Exit

End Function















Message #3 by Lonnie at ProDev <prodevmg@y...> on Tue, 26 Feb 2002 07:17:03 -0800 (PST)
--0-1394274937-1014736623=:77016

Content-Type: text/plain; charset=us-ascii





 Why not put it in the form's On Current event?

  njfarrell@h... wrote: I want to lock a record in access depending on whether one of its own 

field values says yes or no.

I wrote a module which runs as a macro behind the next,previous etc 

buttons. It works well except for the last record. For some reason it 

won't see what value is in field for this record.when your clicking the 

next button it workas fine till here. It won't work either for the find 

button. Heres the code any suggestions would be appreciated. Oh yeah this 

locks the form rather then the record

Function Locks()

On Error GoTo Locks_Err



Dim lngrecordnum

Dim dbMyDB As Database

Dim rsMyRS As Recordset

Set dbMyDB = OpenDatabase("DuraporeComplaintsDatabase2001.mdb") 

Set rsMyRS = dbMyDB.OpenRecordset("Complaints Table", dbOpenDynaset)

rsMyRS.MoveFirst 'Move to first record



lngrecordnum = Forms!

frmNotificationofComplaint.CurrentRecord 'find current 

record on form



rsMyRS.Move lngrecordnum - 1 'move to record 



If rsMyRS!Notification_approval = "True" Then

Forms!frmNotificationofComplaint.AllowAdditions = False

Forms!frmNotificationofComplaint.AllowDeletions = False

Forms!frmNotificationofComplaint.AllowEdits = False

Else

Forms!frmNotificationofComplaint.AllowAdditions = True

Forms!frmNotificationofComplaint.AllowDeletions = True

Forms!frmNotificationofComplaint.AllowEdits = True

End If



Locks_Exit:

Exit Function



Locks_Err:

Resume Locks_Exit

End Function








Lonnie Johnson ljprodev@y... 

ProDev, Builders of MS Access Databases

Let ProDev build your next MS Access database application. 

http://www.galaxymall.com/software/PRODEV 



Get paid cash every time you receive email!

Sign up FREE at: http://www.MintMail.com/?m=975303





---------------------------------

Do You Yahoo!?

Yahoo! Sports - Coverage of the 2002 Olympic Games



  Return to Index