If testfield is a text field it is possible that it is NOT NULL but contains a
zero-length string. You can change the IIF to test for both conditions
IIF(IsNull(TestField) or TestField = "", "Dear " & [Known As],"Dear Sir")
The only thing I can think of is that you have some form of corruption on the
form/subform that is causing the problem. Do you by any chance have the
"dreaded" Name Autocorrect option enabled? If so, this can cause this kind of
problem.
Tools: Options: General tab.
I would try Unchecking that and compacting your database. If that doesn't fix
the problem, then check out the following from Allen Browne.
From: Allen Browne
Okay, so something has gone haywire with this database. Suggestions to recover it:
1. Make a backup copy of the mdb file, without overwriting any existing
backups, in case something goes wrong.
2. Uncheck the boxes under:
Tools | Options | General | Name AutoCorrect Explanation of why:
http://allenbrowne.com/bug-03.html
3. Compact the database to get rid of this junk:
Tools | Database Utilities | Compact
4. If the tables are attached, open the data file, and repeat steps 1 - 3 for
that file as well.
5. Close Access. Decompile the database by entering something like this at the
command prompt while Access is not running. It is all one line, and include
the quotes:
"c:\Program Files\Microsoft office\office\msaccess.exe" /decompile
"c:\MyPath\MyDatabase.mdb"
6. Open Access, and compact again.
7. Open a code window.
Choose References from the Tools menu.
Uncheck any references you do not need.
For a list of the ones you typically need in your version of Access, see:
http://allenbrowne.com/ser-38.html
8. Still in the code window, choose Compile from the Debug menu.
Fix any errors, and repeat until it compiles okay.
9. Compact again.
At this point, you should have a database where the name-autocorrect errors
are gone, the indexes are repaired, inconsistencies between the text- and
compiled-versions of the code are fixed, and reference ambiguities are resolved.
If it is still a problem, the next step would be to get Access to rebuild the
database for you. Follow the steps for the first symptom in this article:
Recovering from Corruption
at:
http://allenbrowne.com/ser-47.html
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
Hi John and thanks for trying to help. Unfortunately it still isn't working...
The names of the form and the subform control are all correct, and I have
tried various names for the aberrant control including [Add200] alas to no
avail.
You are quite right that the macro "can't see" the control... but I don't
know how to make it see it. It seems to see other controls on the subform
(some labels and texts etc.) but not the 2 buttons I'm trying to use (Add200
and Remove200).
What's even more bizarre is that if I use the expression builder... it can
see everything including the controls, but if I cut and paste what the
builder sees... the macro still can't see it with the same error: "The
control name 'Forms![Contact Details]![200 Club subform].Form.[Add200]' is
misspelled or refers to a control that doesn't exist"
I've also noticed another weird irregularity: I have 2 fields in a table
[Known as] and [Forename] that I can add to a form that display correctly,
but if I have 2 more fields on the form with the syntax:
iif(isnull([testfield]),"Dear "&[Known as], "Dear Sir") and
iif(isnull([testfield]),"Dear "&[Forename], "Dear Sir")... one displays the
value ("Dear Fred") but the other does not ("Dear ").
There seems to be no reason why these things don't work... either that or
I'm missing something.
Can you think of anything else?
Jan