I did what you said, but it's still not working. Is Me.OpenArgs the literal
I should be using or am I supposed to subsitute a value here?
Thanks!
Meryl
fredg said:
I have a Contacts form that can be opened by itself or from Organization form.
If the Contacts form is opened when the Organization form is opened, I want
the organization field (in contacts) to default the org-id in organization.
I put this code in the default property of the org-id field in Contacts,
however, it does not work.
Iif(forms![frmOrganizations].isloaded = true, [frmOrganizations]!
[Org-Id],Null)
Can someone tell me what I'm doing wrong and how to fix it?
Many thanks,
Meryl
If the form is opened from the frmOrganization, do it this way:
Docmd.OpenForm "Contacts", , , , , , Me.[Org-ID]
Next ... code the Contacts Load event:
If Not IsNull(Me.OpenArgs) then
Me![Org-ID].DefaultValue = """" & Me.OpenArgs & """"
End If
If the form is opened from the frmOrganization, the Contacts [org-ID]
default value will be whatever the value of that field was in the
calling form (but NOT if it is an AutoNumber field).
That code I gave you works. And yes, it is Me.OpenArgs (literally).
Look it up OpenArgs in VBA help.
Change the code.
In the frmOrganization write:
MsgBox "Sending 'Org-Id' " & Me.[Org-ID]
DoCmd.OpenForm "Contacts", , , , , , Me.[Org-ID]
In the Contacts form Load event write:
MsgBox "Receiving OpenArgs " & Me.OpenArgs
If Not IsNull(Me.OpenArgs) then
Me![Org-ID].DefaultValue = """" & Me.OpenArgs & """"
MsgBox "Default Value " & Me![Org-ID].DefaultValue
End If
Open frmOrganization and then do whatever you do to open the second
form.
You will get a message box giving the value of [Org-ID} of the current
record displayed in frmOrganization. Click OK. Then the Contact form
will open.
When the contacts form opens you will get a message box giving the
value of OpenArgs. It should be the same value as the previous
message. Click OK.
You will then get the DefaultValue of the [Org-ID]. It should be the
same as the 2 previous messages.
If there is a difference, look at your code previous to that point.
If you cannot still find a problem, then copy and paste into a reply
the exact code you have written, with the values given by each of the
3 message boxes.
By the way, you are aware, I hope, that a control's default value is
only usable when a new record is entered and has no effect on already
existing records.