How to lock record from changing? [Access 2010] - ms-access

I'm doing a small project as a part from my course in access; we use Microsoft Access 2010 but the database itself is 2007.
My main problem is: how to lock a record from changing after a value in the record changes a value.
In my case, the value changes is an option box that changes from open to close.
Also, the change itself is triggered by change in other values; I tried to make a macro for it... didn't go as good as I hoped.
The macro should change value A from "open" to "close"
when i tick check box B
and the value in text box C in not null.
Thanks for the help

Related

display control doesn't have checkbox

I have a lot of checkboxes (with yes/no fields in the underlying tables) and lately Access has been crashing a lot. After some research it seems null values in the checkboxes could be to blame, so I set out to follow Allen Browne's instructions (http://allenbrowne.com/NoYesNo.html) for replacing them with number fields. Everything was going great until I got to the step where I set the display control to 106 (checkbox). This is not an option in the table and I don't understand why. I set my table up like he stated but I only have the option for a textbox, listbox, or combobox.
I also tried just typing 106 into the Display Control field, but it gives me an error that it isn't an item on the list. In his article, he mentions to fix the error above to use SetPropertyDAO(), but I have no idea what that means, how to do it, or where to do it. Do I built it in code somewhere? The link he has brings you to a script where he uses that to fix his printers or something.
Close your table.
Open Immediate Window with Ctrl+G
Paste the code:
CurrentDb.TableDefs("Table1").Fields("Field1").Properties("DisplayControl") = CInt(acCheckBox)
Replace table and field name to your names.
Run the code by putting the cursor at the end of the line and hit Return.
If you get an error, open the table in design view, and set the display control to something (it doesn't matter what), save and close, repeat.

Unfreezing columns in a subform in Access

I have a form with a subform that displays records, and the user is able to rearrange that subform and save their preferences. This means they can change the width of the columns, the order, hide columns, etc. and save their changes at any time, and those changes are applied when the form next loads. This is done by saving the preferences in a table and then pulling those preferences from the table in the subform's Form_Load event. This all works fine, but I'm trying to add the ability to save frozen columns as well. I'm able to track how many columns are frozen, and I'm also able to restore the order of the columns, so it should be a simple matter to unfreeze all of the columns and then refreeze the first X columns.
I know that I can use 'RunCommand acCmdUnfreezeAllColumns' to unfreeze all of the columns. I also know that I need the focus to be on the form, so I tried to do myForm.setFocus (where myForm is a reference to the subform) before unfreezing the columns. This gives the error "There is an invalid method in an expression". I thought maybe this was because you can't set focus to a form with enabled controls, so I tried myForm.Controls(0).SetFocus instead. This doesn't give an error, and it seems to set the focus to the first cell in the subform based on the value of Screen.ActiveControl (and the fact that the cell has the focus after the form loads). However, I then get the error "The command or action 'UnfreezeAllColumns' isn't available now." on the line RunCommand acCmdUnfreezeAllColumns. I also thought maybe I was having problems because I was trying to focus in a load event, so I tried calling the repaint method first, but that didn't make any difference. I thought about unfreezing all of the columns in the design view so that I wouldn't need to unfreeze them at runtime, but the user may not have any preferences saved and I want some columns frozen by default.
I'm running out of ideas on this. What exactly needs to happen for the command to unfreeze all columns to work? Or is there an easier way to do this that I'm missing? The solution needs to be versatile enough to work on any subform with any field names. Note that I do have a list of the field names that were present when the user saved their preferences, but I cannot guarantee that they will still all exist when their preferences are restored.
This normally worked for me:
myForm.SetFocus
RunCommand acCmdUnfreezeAllColumns
However, sometimes it failed, so I tried to repeat it:
On Error Resume Next
myForm.SetFocus
RunCommand acCmdUnfreezeAllColumns
If Err.Number <> 0 Then
myForm.SetFocus
RunCommand acCmdUnfreezeAllColumns
End If
On Error GoTo 0
That nearly always worked, but the menu commands are not 100% reliable.

MS access form combo box row source based on current field value

Newb in Access (version I used: 2010) and VB. :(
I have a form and a table both named "issues", a combo box named "statusfield" (value list: open, reopen, wip, closed).
The form loads the content of table "issues" per record. One can modify the field value of records.
The aim is to show the available value list based on the current status of an issue.
For example, if the current value of "statusfield" is empty, when one clicks the combo box, available status would be "open;reopen;wip", and if the current value of "statusfield" is "open", then available status would be "wip;closed".
Could one explain as detailed as possible please? Appreciate it!
Add this code in the AfterUpdate event of the combobox
If Me.statusfield.value = "open" Then
Me.statusfield.RowSource = "wip ; closed"
End If
So I redesigned the database, created the one to many mapping in (Database tools -> Relationship), with the same vba, everything works as designed. Cheers!

Access 2013 Cannot Set Lookup Display Control to Text Box

I have added a new field to an existing database and set the Data Type to Yes/No as shown in Pic1.
This defaults to Check Box. If I then try and select Text Box (as shown Pic2) it immediately reverts to Check Box. Combo Box can be selected successfully.
Can someone advise why I cannot select Text Box? There are already other fields configured in this manner in my database. Also of note if I change these other fields to Check Box and try to change them back to Text Box, they also revert to Check Box.
I am facing the same problem. For some reason you cannot choose text box as lookup option.
There are two workarounds:
Choose combo box and
Row Source Type: Value List
Row Source: -1;Text for yes;0;Text for no
Column Count: 2
Column Widths: 0
Source, from MS answers forum
Or select datasheet view, click fields under table tools, select more fields and go to Yes/No then select Yes/No. Now you can choose text box as look up option.
I was able to confirm the change in behaviour between Access 2010 and Access 2013. Access 2010 allows us to choose "Text Box" for a Yes/No field. In Access 2013 the "Text Box" option is still there in the drop-down list, but when selected it immediately switches to "Check Box".
I'm afraid that's just the way Access 2013 works. If you really need to make the change you could try to locate a machine with Access 2010 and use it.
Try using :
CurrentDb().TableDefs("YourTable").Fields("YourField").Properties("DisplayControl")=109

Data in Combo Box in form not relfecting in Access Report

I have been battling with this problem for weeks now and simply cannot find a solution.
I am using MS Access 2007
I have a table caled "Policy Information" where all of my data is stored. I have created a combox box to autofill a few text fields using a query called "BC Allocation Query". By choosing from the combox269 field I created then 6 other text fields are automatically completed. I used the function =[Combo269].column in the control field of the text field I want auto-completed.
This all works great however I cannot seem to relfect the information from the text boxes which are auto-completed to relfect in my Access Reports whcih I have set up.
Please can someone assist me withthis before I jump off a cliff:)
Are these text fields on the form bound to fields in the source for the form? If not, they are unbound, and you need to write code to save this information into the table when you navigate away from the record or close the form. If they are bound, you need to programmatically force a save of the record when VBA changes values, otherwise - you might get the dreaded 'values changed by another user' verbage in an error.