Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2011
    Posts
    20

    Post Setting Record Readonly

    Hi

    I created a form in access which has multiple fields.I have locked the rows to prevent edit or delete after inserting the record by means of allowedits and allowdelete properties of the form.
    How ever i need to change a field alone after insertion.Hence i wrote a piece of code in that control's key press event stating ,Raising the input box and getting the value and then im updating that field.
    But after updating that field the entire record went to editable mode after i wrote the following code.
    Code:
     a = InputBox("Enter the STATUS", "Option")
            Set db = CurrentDb()
            dsql = "UPDATE tbl_PaperTeam SET tbl_PaperTeam.Status = '" & a & "' WHERE tbl_PaperTeam.ID=" & txtID & ""
            db.Execute dsql, dbFailOnError
            Set db = Nothing
            MsgBox "Status Updated", vbCritical + vbOKOnly, "Error"
            Me.AllowEdits = No
    After i executed the above code.all fields went to editable mode

    So please assist me what should be done to make the entire record read only
    after updating a single field
    Last edited by ganeshvenkatram; 06-23-2011 at 01:22 AM. Reason: Spell mistake

  2. #2
    pkstormy's Avatar
    pkstormy is offline Access/SQL Server Expert
    Windows XP Access 2003
    Join Date
    Mar 2010
    Location
    Madison
    Posts
    682
    You could also have set the .locked property to true or false for each of the fields on the form versus the allowedits.

    My guess is that somewhere (prior to the code you posted), the allowedits is set to true and that this code is possibly failing (I'm not sure since this is DAO and I code using ADO) where it then doesn't execute the me.allowedits = No (shouldn't it also be me.allowedits = False versus No?)

    I would change the me.allowedits = No to me.allowedits = False and put in a message box after the me.allowedits = False (ie. msgbox "AllowEdits now set to False" and see if it popups up that message which would indicate that it executed the me.allowedits line of code.)

    With using the Inputbox code, don't forget to also test if someone clicks the cancel button or doesn't enter any value and clicks ok.

  3. #3
    Join Date
    Jun 2011
    Posts
    20

    Post Re: Setting Record readonly

    Quote Originally Posted by pkstormy View Post
    You could also have set the .locked property to true or false for each of the fields on the form versus the allowedits.

    My guess is that somewhere (prior to the code you posted), the allowedits is set to true and that this code is possibly failing (I'm not sure since this is DAO and I code using ADO) where it then doesn't execute the me.allowedits = No (shouldn't it also be me.allowedits = False versus No?)

    I would change the me.allowedits = No to me.allowedits = False and put in a message box after the me.allowedits = False (ie. msgbox "AllowEdits now set to False" and see if it popups up that message which would indicate that it executed the me.allowedits line of code.)

    With using the Inputbox code, don't forget to also test if someone clicks the cancel button or doesn't enter any value and clicks ok.


    Thanks for ur response.

    Here i cant use lock property , since if i set the locked property to yes, then i cant able to key in when inserting the new record and also if set and unset again when insert the entire records will be editable. So i cant go with that option.

    I didnt set Allowedits to true anywhere in my code since its unworthy . Can u plz give me any other suggestion???

  4. #4
    pkstormy's Avatar
    pkstormy is offline Access/SQL Server Expert
    Windows XP Access 2003
    Join Date
    Mar 2010
    Location
    Madison
    Posts
    682
    Since it sounds like you only want to update 1 field, here's 2 options I can think of:

    1. Put a button on the form which opens a popup type form that has this 1 field and allows editing of it.

    2. Write a function (in a module) which will update the record with whatever info. You again, could have a button which when clicked prompts for a value and then writes to the recordset.

    There are some examples in the code repository. I can't recall which one but several of them show how to write functions in a module which updates records.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 9
    Last Post: 04-04-2011, 11:13 AM
  2. Setting SQL = string
    By jasonbarnes in forum Programming
    Replies: 7
    Last Post: 02-18-2011, 11:02 AM
  3. Control linked to subform is readonly
    By degras in forum Forms
    Replies: 1
    Last Post: 11-23-2010, 09:21 PM
  4. readonly password protect
    By mlgehle in forum Security
    Replies: 1
    Last Post: 03-13-2010, 08:59 PM
  5. tabular forms - setting values per each record
    By Daytona675 in forum Forms
    Replies: 0
    Last Post: 11-25-2008, 09:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums