MS Access Form events, VBA - forms

I have 3 fields in an access form.
Field 1 - is a text field pre-populated with some data. There are no null records
Field 2 - is a text field pre-populated with some data. It can either have a value or be null.
Field 3 - Is a text field. The user will enter information into the field.
There is a rule. If there is a null value in field 2, then field 3 will equal the value from field 1 and so I want it to automatically populate field 3 from field 1. if the value is not null, then the user will populate the field record manually.
I have set up a form load event to:
If Me.field2 = "" Then
Me.field3 = Me.field1
The problem I am having is, the user may want to change the pre-populated value of field 1 and if the corresponding field 2 record is blank, I want field 3 to be updated with the same value the user changed in field 1. I don't want to have to reload the form all the time for this update to occur. I've tried the above syntax in a After_Update event and a change event, but it's not updating.
Can anyone suggest what I am doing wrong?
Thanks,
Mike

another test for empty string or null is
if len(field1 & "")=0 then 'do null stuff
appending an empty string to null or an empty string results in an empty string, which you can then test for length

Mike's already got his answer, but I'll give a fuller answer in the form of an explanation.
The problem here is that you are trying to compare a field that is null to an empty string. It's like you've done
if null = "" then
'do stuff
end if
The problem is when null is used in a comparison, the result is always null - which causes the if to evaluate to false. You can't even do this:
if not(null) then
'do stuff
end if
or
if not (null <> "") then
'do stuff
end if
The conventional solution is to us isnull(x), which evaluates to true if x is null.
As Tim Williams indicate, you can use:
IsNull(x) or x=""
Some might consider the x="" to be redundant if x can only return null for an empty string.

This works too:
if Nz(Field1, "") <> "" then 'do null / empty stuff

Related

In flutter TextFormField I can't clear the value when using double.parse

I am creating a dialog that allows a user to make a payment and it subtracts it from their current balance.
So if their balance is $100 and they type $25 into the form field and hit submit the balance is now $75.
That all works. My problem is if I erase everything in the TextFormField and hit submit the $100 balance is now $98.
That's because when I erase the value the first character sticks in the value and I can't delete it by hitting the delete key.
When I print the value, hit the delete key, and look at the console it looks like this...
25.00
25.0
25.
25
2
No matter how many times I hit delete, the 2 won't erase.
I narrowed it down to double.parse being my problem. Here is the code:
onChanged: (val){balance = debtBalance-double.parse(val);
print(val);},```
I think this is because parse method fails when provided with empty or null value. It doesn't really make sense to parse an empty string anyways, so just use default value 0 in those cases.
balance = debtBalance - ((val ?? '').isEmpty ? 0 : double.parse(val));
This code snippet checks if new text value is empty, and if so it substracts 0 instead of parsing.

Multiple Conditions in MailMerge Field

I would like to include up to 3 conditions in a MailMerge field. Below is my current field which returns 1 if checkbox1 is checked.
if"<<cb1>>"="Yes" "Checked""Unchecked"
I would like to include checking of additional cb2 and cb3, to check if any of them are checked.
May I know how can it be done?
p.s. I left out the { } colons which I am not sure if it will be required here.
Edit: Tried the following structure but the output was Yes
if
"if"<<cb1>>"="Yes" "1""0""
+
"if"<<cb2>>"="Yes" "1""0""
+
"if"<<cb3>>"="Yes" "1""0""
>0
"1 or more checked""None checked"
Try a field coded as:
{IF{={IF«cb1»= "Yes" 1 0}+{IF«cb2»= "Yes" 1 0}+{IF«cb3»= "Yes" 1 0}}> 0 "1 or more checked" "None checked"}
Note: The field brace pairs (i.e. '{ }') for the above example are all created in the document itself, via Ctrl-F9 (Cmd-F9 on a Mac or, if you’re using a laptop, you might need to use Ctrl-Fn-F9); you can't simply type them or copy & paste them from this message. Nor is it practical to add them via any of the standard Word dialogues. Likewise, the chevrons (i.e. '« »') are part of the actual mergefields - which you can insert from the 'Insert Merge Field' dropdown (i.e. you can't type or copy & paste them from this message, either). The spaces represented in the field constructions are all required.
For example, you can create a field with logic such as: “If Condition 1 is met, then if Condition 2 is also met, display Result 1”. This is equivalent to saying “if both conditions are met, display Result 1”; but unfortunately you can't use “and” in Word fields.
Such a field would look something this:
{ IF [Condition 1] { IF [Condition 2] [Display Result 1] "" } "" }
The easiest way to create nested fields of this type is to create them separately, then cut and paste one field into the other.
Source

Default Value Expression for Optional String Input iReport

I'm using PostgreSQL as DBMS, in my current report I need an optional String parameter to get records by Id, which is a String field.
So I set the Default Value Expression to:
($P{Param} == null || $P{Param}.equals("")) ? "" : "AND id='" + $P{Param} + "'"
When the field is empty the report is created without issues, but when I enter a valid Id the compiler complains:
Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at or near "160E0"   Position: 3126
Just like if I was adding double quotes after and before the value I'm passing. Somebody know how to handle this problem when using String values?
I guess, you've created one Parameter, named Param and in your query you have $P!{Param}. Thing is, default value is set only when parameter stays NULL after prompting, so when you input your ID, ${Param} value is passed into query as it was inputed by user (without AND id=' part).
Try creating second parameter, lets name it $P{input}; set its default value to your expression, "Use as a prompt" value to false. Pass it to your query ($P!{input}). Now, you have your ${Param} for prompting and when it's value is set to the desired ID, $P{input} is set to your query condition.

Enter a query in a default value expression

In Jasperreports I would like to enter a Default Value Expression to a Parameter as a Query string to be able to dynamically provide the user with a default value that is correct, but not force him to choose it.
Is there anyway?
I guess the result should look something like this (even though it doesn't work):
I am using this for a form with a single-value selection method (the user can write which ever number he/she wants but I want the default value to be selected from the database).
Here's how I handle this:
The user selects a value from an input control (in my example, I will call it $P{time_toggle}). Then, I have another parameter ($P{time_constraint}) that takes the user input from $P{time_toggle} and decides what SQL string to inject into the main query based on it. The default value expression for $P{time_constraint} looks like:
$P{time_toggle} == "rolling_quarter" ? "..." : (
$P{time_toggle} == "rolling_30_days" ? "..." : (...
)
)
Then, in my main report query I reference $P{time_constraint}:
SELECT * FROM tblTable WHERE $P!{time_constraint}
To set a default time period, I set the default value expression for $P{time_toggle} to my desired default.

Access 2010 Trying to Enter a unique record through Form

I'm trying to input an error check for my form. I have the user entering the name and I would like a prompt to inform them if they are attempting to use a Name already in the records.
Example: the Person table has 3 records with FNames being: Jeff, Kyle, Darren.
If on the add person form in the Fname Box Kyle is entered, the after update event will notify the user that this name has been claimed and null the field. Where as if Greg was enter no notifications will occur.
I just don't know how to compare a text field value to values in a filtered query list, and Google searches have other loosely related links in the way.
Thank you for help!
If all fnames must be unique, add a unique index to the table. This will prevent duplicates being entered. The form error property will allow you to provide a custom error.
You can also check if the name exists in the Before Update event of the control.
In this example, the control and field are both called AText. Generally, you should rename controls so they are not the same as fields.
Private Sub AText_BeforeUpdate(Cancel As Integer)
Dim IsOk As Boolean
''One of the very few places where the .Text property is used
sLookUp = Me.AText.Text
IsOk = IsNull(DLookup("Atext", "Table1", "Atext='" & sLookUp & "'"))
If Not IsOk Then
MsgBox "Found!"
Cancel = True
End If
End Sub