Trigger MS Access Table Field Validation Text - ms-access

I have a field in an MS Table set to number for month number.
field type = Number
Field Size = single
Validation Rule= (Not Is Null) or (>0 and <13)
Validation Text = The month must be between 1 and 12
Required=Yes
If no data is entered I get the system error "You must enter a value in the dim_daod.daod_month field."
I want it to trigger the Validation Text instead.
What should the Validation Rule be?

You want your validation rule to be
(Not Is Null) And (>0 And <13)
instead.
If you still have the Required parameter set to yes then you'll need to intercept that the "You must enter a value in the field" message on your data entry form.
Alternatively, you can set the validation at the table level using the same criteria and message
( daod_month Is Not Null) And (daod_month>0 And daod_month<13)

Related

How to disable one field by filling a value in another field in a MS access for

I have created a pharmacy database table. In addition to other fields, I have three fields: 'TypeTxn' (Text field) with Receipt, Issue and Loan Issue as three options in a drop down menu, Qty_R and Qty_I (both number fields depicting quantity received and issued). I want, that when TypeTxn is being filled and if 'Receipt' is selected by the user, the Qty_I field should get disabled and when Issue is selected, the Qty_R field should get disabled, i.e. one should not be able to fill data in that field. My knowledge about coding is almost nil. I have tried this code, but it does not work. Can someone help me to create the above mentioned operation in the MS Access Form?
Private Sub TxnType_AfterUpdate()
' by default enable two fields Qty_R/Qty_I
Me.Qty_R.Enabled = True
Me.Qty_I.Enabled = True
' test the value entered by user in TxnType field and hide fields as required
Select Case Me.TxnType
Case "Receipt"
' if the user has entered Receipt, lock field Qty_I
Me.Qty_I.Enabled = False
Case "Issue", "LoanIssue"
' If the user has entered Issue, LoanIssue lock field Qty_R
Me.Qty_R.Enabled = False
End Sub

Access Data Macro function ‘Updated’ fails with Combo Box

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

Add validation to numbers stored as text in Access

Field name in MS Access table - s1
data type - text
I use this field to store student marks.
'AA' will be entered if the student is absent and therefore I have selected text data type for this field
I want to restrict data entry to minimum marks = 0 and maximum = 75
How do I enter validation rule in this text field?
You may want to reconsider your decision to store the values as Text. You could store them as Numeric and just use a custom Format property to display AA when the value is Null (which is allowed when "Required=No"):
Set maximum length of the text of the field to: 2
Set validation rule to: "AA" Or Between "00" And "75"
Also, apply an inputmask to force two characters, or make sure that values between 0 and 9 are entered as 00 and 09.
In design view for your table that will store the student mark, select the student mark field.
In the field properties in the lower part of the screen set the Field Size to 2, the Validation Rule to "AA" Or Between "0" And "75" and then in the Validation Text field, write a helpful message to the user describing the valid data they can enter in to this field:
If the user tries to put in data outside the restrictions of your validation rule, they'll see your validation text message and won't be able to save their invalid data:

Microsoft Access - query checkbox based on textbox

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);

MS Access Form Insertion Hidden value

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.