Welcome to the forums!
I have records that in certain circumstances, I don't want the user to have access to update them. I also want the background color to be changed for these records.
In Access, how can I accomplish this?
If you don't want the users to even see these records you should use a query to filter out the records that the user should not be able to see.
If you still want them to be able to see the records then the easiest method of preventing records from being edited is to set the Allow Edit tab in the Form\Data property to No. I'm guessing that your certain circumstances might also extend to deletion; setting Allow Edits to No won't prevent deletion of the record, for that you'd need to set the Allow Delete property to No too.
Both of the above work for all records in a Forms Record Source. As you only want to prevent the editing of records 'in certain circumstances' you will need to be able to identify which these records are; a field 'editable' of the Yes/No variety would suffice (added to the underlying table), if you want to control deletion seperately then you'd need an additional field for that.
To prevent the editing (to 'lock' the record) you would then put code in the On Current event of the form to test the value of your 'editable' field and, if it is 'No' then either:
- Change the Allow Edit property to No, or
- Set the Locked property of the controls on the form to Yes.
Don't forget that the code in the On Current event should reset the 'locks' above if the 'editable' field is set to Yes.
With regards to changing the backgrounds of the controls, changing the Locked property of a control to Yes will do that automatically. Unfortunately changing the Allow Edit property to No does not change the background colour of the controls, for this you would have to go through all of the controls that you need to change. Search the forum for 'For each ctl' for solutions on how to iterate through all of the controls on a form. Becareful with this method though, because if you use your own buttons to control navigation, or exiting from the form, then you may end up affecting them too, it may be better to go through each control manually (if you set up a sub routine to carry out the change, according to the status of the editable field, then you could use the same routine to both disable and enable the fields, or to change the background colour, as required).
I was thinking of the datagrid, would this work? If so, I was wanting a bit more information on how to use the datagrid in MS Access. Where would be a good place to look?
I'm afraid that I am not familiar with 'datagrid', and the Access help file doesn't return anything, so I cannot comment. A search in the forums shows that there are a quite a few results, mostly related to VB, VB.Net and ASP/ASP.Net (i.e: the programming forums rather than the Forms forum), perhaps you should have a look at some of them for this part of your question?
HTH
Tim