Thanks for copying and pasting what you have in the code.
Me.Visit = Nz(DMax("[RecordNumber]","[DaysView]","[Last Name] = """ &
[LastName] & """ And [First Name] = """ & [FirstName] & """ And [MI] =
"""
&
[M_I] & """ And [MR_Number] = " & [MRNumber] & " And [IRB Number] = """
&
[IRBNumber] & """""),0)+1
The last set of quotes should be 4 double quotes ", you have 5.
Yes, I saw the second message, let's see if this helps first.
--
Wayne Morgan
MS Access MVP
we seem to be getting nearer something more useful.....
i pasted your string and modified the lefthand member into th current
event
property vba thus
Me.Visit = Nz(DMax("[RecordNumber]","[DaysView]","[Last Name] = """ &
[LastName] & """ And [First Name] = """ & [FirstName] & """ And [MI] =
"""
&
[M_I] & """ And [MR_Number] = " & [MRNumber] & " And [IRB Number] = """
&
[IRBNumber] & """""),0)+1
although when looking at it, it is on one (1) line; nevertheless when i
went
to compile it, it gave me an error first about a missing ")" and now
it's
just talking about 'Syntax Error'?
your Dirty Event idea sounds goog (did you read my posting about which
are
going to make the PK elements)?
-ted
:
Yes, you may be able to do this in a VBA event. If you use the form's
Current event then check to see if you're at a new record, you could
assign
a value to the control at that point. To do this in the Current event:
If Me.NewRecord Then
Me.NameOfControl = Nz(DMax("[RecordNumber]","[DaysView]","[Last
Name]
=
""" & [LastName] & """
And [First Name] = """ & [FirstName] & """ And [MI] = """ & [M_I] &
"""
And
[MR_Number] = " & [MRNumber] & " And [IRB Number] = """ & [IRBNumber]
&
""""),0)+1
End If
There is one potential problem with this. If the value is set by the
Default
Value property, it won't "dirty" the record. This prevents going to a
new
record but not making any manual entries from causing a new record to
be
created. However, doing this in the Current event will "dirty" the
record.
You'll also need to see if the user makes any other entry and Undo the
record if they don't.
Another option is to place the above code in the form's Dirty event.
That
way the value will only be inserted if the user first makes another
entry
to
create the record. If the user made that first entry in this field,
then
the
code would overwrite their entry. So you would need to keep the user
from
making their first entry in the new record in this field.
--
Wayne Morgan
MS Access MVP
i opened a blank word document which i set to be in landscape mode
and
whose
margins i set to as wide as possible along with reducing the
fontsize
maximally. i pasted the script you sent as is onto the said document
but
yet
even so it didn't fit onto one line but spilled over slightly onto
the
2nd
one. i selected the first line and pasted it in the Default Value
window
and
then reprised that with the 10 or so characters remaining from the
2nd
one.
still no cigar when i view the form but i suppose that was a long
shot
anyway.
the infor'n in the file is 'sensitive' and i suppose i could remove
all
but
the two tables and forms involved in this thread, delete all but a
few
records and alter the names of the persons described to anonymize
it.
still i
sort of wish it didn't have to come to that. which brings me to my
next
'idea' -- would it be possible to use an event property instead of
the
entering the expression into the 'Default Value' property? i just
read
something on the web which seems to me to suggest that conditional
defaults
could be vba-ed into an anfter update event? i'm thinking about
workarounds....
-ted
:
Copying "as is" will cause a problem. The news reader has wrapped
it
to 4
lines. It needs to all be on one line. If that still doesn't get
it,
please
zip and forward me a copy of the file (or a link where it can be
downloaded)
to
[email protected]. Attach a note telling me where in the file
to
look.
--
Wayne Morgan
MS Access MVP
hi wayne,
i pasted the expression below which i'm copying and pasting 'as
is'
from
the
'Default Value' property's setting below for good measure:
=Nz(DMax("[RecordNumber]","[DaysView]","[Last Name] = """ &
[LastName]
&
"""
And [First Name] = """ & [FirstName] & """ And [MI] = """ & [M_I]
&
"""
And
[MR_Number] = " & [MRNumber] & " And [IRB Number] = """ &
[IRBNumber] &
""""),0)+1
and still the #Name? appears in the 'Visit' control when viewing
this
sub-form in datasheet view on the mainform. arrrgh :-(