I have a table with many data rows. This table contains the field "title".
Some of the data rows have already something predefined in that field and the other data rows have this field empty.
My goal is to create a form where users can do the following for every data row: If the field "title" is filled, this field can't be edit. If the field "title" is empty, the user can write something in this field.
I haven't found a solution yet. I tried with calculated fields but these can't be edited.
Also this table and form are for web access, so the possibilities are limited.
Thanks in advance.
Run embedded macro in form OnCurrent event to execute SetProperty action. Use it inside an If Then Else conditional to set Enabled property.
If IsNull(Forms!formname!controlname) Then
SetProperty
ControlName: your control name
Property: Enabled
Value: True
Else
SetProperty
ControlName: your control name
Property: Enabled
Value: False
End
This code assumes field will not have empty string. I do not allow empty strings in fields.
Related
I have the following piece of code located in the open event of a form.
If GetUserName = "Bob" Or GetUserName = "Ned" Then
Me.cbo_Position2.LimitToList = False
Me.cbo_Position2.AllowValueListEdits = True
Me.cbo_Position2.ListItemsEditForm = frm_MasterDropDown_lookup
End If
I'm using this code to set who can edit a combo box list. The combo box is bound to a field on the form and the combobox info is in a separate lookup table. What I want to know is whether or not these properties can be set as the form opens.
When I run this code, it executes with no errors but the properties do not change. I also tried doing 'Me.Refresh' at the end but that did not help. My assumption at this time is that they can't be "set on the fly" so to speak. If not, I was wondering if there is something I'm missing to get this to work.
TIA,
Tim
From Access help:
1.If you set the combo box's BoundColumn property to any column other than the first visible column (or if you set BoundColumn to 0), the LimitToList property is automatically set to Yes.
2.When the LimitToList property of a bound (bound control: A control used on a form, report, or data access page to display or modify data from a table, query, or SQL statement. The control's ControlSource property stores the field name to which the control is bound.) combo box is set to No, you can enter a value in the combo box that isn't included in the list. Microsoft Access stores the new value in the form's underlying table (table: A database object that stores data in records (rows) and fields (columns). The data is usually about a particular category of things, such as employees or orders.) or query (query: A question about the data stored in your tables, or a request to perform an action on the data. A query can bring together data from multiple tables to serve as the source of data for a form or report.) (in the field specified in the combo box's ControlSource property), not the table or query set for the combo box by the RowSource property. To have newly entered values appear in the combo box, you must add the new value to the table or query set in the RowSource property by using a macro or Visual Basic event procedure (event procedure: A procedure that is automatically executed in response to an event initiated by the user or program code, or that is triggered by the system.) that runs when the NotInList event occurs.
Example for setting property:
Forms("Order Entry").Controls("States").LimitToList = False
Running Microsoft Office 365, Windows 7 Enterprise.
When working with a test table in datasheet view, a data macro will not detect when the “Status” field changes. The data macro works properly as long as the ‘Allow Multiple Values’ attribute is set to NO. But the function “Updated” does not detect a field value change when the ‘Allow Multiple Values’ attribute is set to YES.
Tbl_TEST:After Update – data macro
If Updated(“Status”) Then
SetLocalVar
Name: RecordID
Expression: =[tbl_TEST].[RecordID]
Else
StopMacro
End If
Look Up A Record In tbl_TEST
Where Condition: =[tbl_Test].[RecordID]=[RecordID]
EditRecord
SetField
Name: tbl_TEST.StatusChange_TS
Value: =Now()
End EditRecord
I tried the following technique, but it too does not detect a change in the “Status” field with multiple values.
If [tbl_TEST].[Status]<>[Old].[Status] Then
Any help would be appreciated.
Data Macros do not support reading of Multi-Valued fields (or attachment fields). If you were to try to log the values using a LogEvent action you will get the following error ( my field is AllPlans)
The field '[AllPlans]' could not be read because it is a multi-value or attachment field.
I suggest doing it the old-fashioned way, using a sub-table, with Multi-Part Key and multiple data rows. Then deal with the changes in that table.
Art
I have a field text field containing dates.
I also have a checkbox named "Delivered"
If the text field contains a date, I would like the "Delivered" checkbox value to be "True" / ticked.
If the text field isNull, the checkbox value must be "false" / not ticked
I have tried the following in the query expression builder of my checkbox:
IIf([DateField]="";False;True)
but I keep getting an error about the expression being built incorrectly?
You are trying to store a Calculation/dependent value in a table based on a field in the same table, this is not advisable and should not be carried forward. Calculations should be done when and where required, like display on Forms, Query to export or Reports to show. More info on Calculation field is available here : http://allenbrowne.com/casu-14.html
If you really want to then you can create an UPDATE Query as,
UPDATE
tableName
SET
DeliveredFieldName = IIF(Len(DateFieldName & '') = 0, False, True);
I have a form TForm based on table T, set up as a datasheet. My goal is to add a filterable column to the datasheet where the column's value is calculated from a query using another column's value.
I tried to do this by adding a text box currentBox to T. The control source for currentBox is:
=DLookUp("name","currentStatus","itemID=" & [ID])
where [ID] is a field in T and currentStatus is an aggregate query on a table that T is related to.
I can filter on all the fields in TForm that are in T. But I can't filter on currentBox, even though it also appears as a column in the form; clicking on the column header doesn't do anything.
I'm guessing the problem is that currentBox is not bound to a field in T; is there a way to work around this?
Here's a VBA solution:
Add a combo box (aka drop-down) object to your form header. This drop-down's source will be an independent query that displays all the values your Dlookup() currently pulls (names?) and stores the itemID. Let's call it ObjPickName in this example.
Add an AfterUpdate event to ObjPickName that will filter your form for you (your form will still be based on T). The code will be something like:
Private Sub Combo_ObjPickName_AfterUpdate()
Me.Form.Filter="[itemID]='" & Me.Combo_ObjPickName.Value & "'"
Me.Form.Filteron=True
End Sub
The way that I ended up solving this was to add a field to T, and have that field updated during the AfterUpdate() event with the value from the DLookup() call. Because the field is now no longer query-based, it can be used to filter the form.
I'm not really sure how to define this.
I have a table that has a few fields, let's call them: ID, Name, and Type.
I have a form that allows the user to add new records via Datasheet view. ID and Type is hidden, and only Name appears. I've setup a Filter that shows only records of a specific Type (i.e. Type = 2)
However, if someone enters a new record into the datasheet, the Type field does not get set. Setting a default value on the field won't accomplish what I want because I have a few Forms that are tailored based on Type, therefore, each needs to submit new records to the same table based on that type.
Is there a way to define what value it should set Type to? I guess I could capture the BeforeUpdate event, and set the value that way, and just hide the column. I was wondering if there is a way "proper" technique, though.
In the form's Before Insert event, you can examine the current Filter expression, parse out the filter's Type value, convert it from a string to a number, and finally assign that number to the hidden control which is bound to the Type field.
So, assuming that hidden control is a text box named txtType, and its control source is a long integer field:
Private Sub Form_BeforeInsert(Cancel As Integer)
Me.txtType = CLng(Split(Me.Filter, "=")(1))
End Sub
Use the appropriate type conversion function in place of CLng() to match the bound field's data type.
That approach should work if you're setting the Filter like this:
Me.Filter = "[Type] = 2"
Me.FilterOn = True
But, if you're using a different method to do the filtering, please give us details about it.