Well, that explains it. Now the question is why di you have
that line of code? And, if a record already exists, doesn't
it already have its PatientID set?
I seems like you may want to set the PatientID for new
records (events?), but there is no reason to set it when the
form is opened.
Very true. PatientID needs to be set for new records, but not for
existing ones (in which the PatientID is already there). Not sure why
the original programmer programmed it that way, but I suspect it had
something to do with the weird way he was populating two tables.
Imagine a many-to-many, but the junction table and one of the tables
on the one side weren't linked. This was the part of the database
model.
When the user opened the form (which was based on the table on the one
side of the m:m), and entered his first character, the AfterInsert
code would open a new ADOB.Recordset and populate the junction table
with the appropriate child fields for both sides of the m:m. Doing
this (I guess) created a value for the junction table's autonumber
(and PK) field. This value was then copied to the form's recordset
(Me.Recordset).
To arrange for new records to have the PatientID set
automatically, get rid of the offending line of code and
change the open form code to use the OpanArgs arguments:
DoCmd.OpenForm stDocName, , , stLinkCriteria, _
OpenArgs:= Me.Parent!PatientID
And add code like this to all the event forms' Load event
procedure:
If Not IsNull(Me.OpenArgs) Then
Me.PatientID.DefaultValue = """" & Me.OpenArgs & """"
End If
This did the trick, and the phenomenon of the Dirty becoming True
simply by clicking a command button (with no real code behind it) has
gone away. I guess I don't see how setting the PatientID via OpenArgs
is any different than setting it via a line like
Forms(stDocName).Controls("PatientID").Value = Me.Parent! (I don't
understand Open Args all that well.)
It seems the above code says:
If Open Args has a value (which it will every time, right? In this
case, it's always set to Me.Parent!PatientID), then make the default
value of PatientID = to the value of OpenArgs (which is always
Me.Parent!PatientID). How is this different than:
Forms(stDocName).Controls("PatientID").Value = Me.Parent!
It seems perhaps the outcome is the same, but the means of getting
there is different.
Thanks for your help.