W
Wim
Hi,
In my Access 2003 database I have a main table with general information and
several other tables that store specific information about subsets of records
from the main table. The tables all have a numeric primary key, always called
ID, and they are in 1-to-1 relationships with the main table with referential
integrity enforced.
General information is entered in the main table using a form, and for every
subset table there is a specific form. The specific forms are opened from the
main form using a command button. To make sure the specific form refers to
the same case as the main form I use the following code:
stLinkCriteria = “[ID] = “ & Me!ID
DoCmd.OpenForm stDocName, , , stLinkCriteria
That works fine as long as I want to display information that is already
there.
But what if I want to input new cases? After completing the main form, I
want the specific form to create a new record with the same ID. I do that by
using the OpenArgs argument, changing the command to
DoCmd.OpenForm stDocName, , , stLinkCriteria, , , CStr(ID)
In the On-Activate-Event of the specific forms I put:
If Not IsNull(OpenArgs) Then
If IsNull(Me.ID) Then Me.ID = CLng(OpenArgs)
End If
I wonder if this is the best way to go about. I understand all this is
accomplished automatically if you use a subform (Link Child and Master
fields), but I find subforms very unpractical in the case of a 1-to-1
relationship. Is there a better way?
To make things easier for the user I want the specific forms to display some
of the information about the case from the main table/form; just displaying
it, without the possibility to change it. Again, this is no problem as long
as the form is showing existing records. I can base the specific form on a
query that includes the fields from the main table that I want to repeat and
put the field names in the Control Source of the controls.
But what if we are creating new records? What do I have to do to make sure
controls on the specific form show information (from the main table) about
the record whose ID has just been set in the Activate Event?
In the case of a 1-to-many relationship, I understand this can be done by a
so-called autolookup query, but what in the case of a 1-to-1 relationship?
I hope you can give me some suggestions on these two questions.
In my Access 2003 database I have a main table with general information and
several other tables that store specific information about subsets of records
from the main table. The tables all have a numeric primary key, always called
ID, and they are in 1-to-1 relationships with the main table with referential
integrity enforced.
General information is entered in the main table using a form, and for every
subset table there is a specific form. The specific forms are opened from the
main form using a command button. To make sure the specific form refers to
the same case as the main form I use the following code:
stLinkCriteria = “[ID] = “ & Me!ID
DoCmd.OpenForm stDocName, , , stLinkCriteria
That works fine as long as I want to display information that is already
there.
But what if I want to input new cases? After completing the main form, I
want the specific form to create a new record with the same ID. I do that by
using the OpenArgs argument, changing the command to
DoCmd.OpenForm stDocName, , , stLinkCriteria, , , CStr(ID)
In the On-Activate-Event of the specific forms I put:
If Not IsNull(OpenArgs) Then
If IsNull(Me.ID) Then Me.ID = CLng(OpenArgs)
End If
I wonder if this is the best way to go about. I understand all this is
accomplished automatically if you use a subform (Link Child and Master
fields), but I find subforms very unpractical in the case of a 1-to-1
relationship. Is there a better way?
To make things easier for the user I want the specific forms to display some
of the information about the case from the main table/form; just displaying
it, without the possibility to change it. Again, this is no problem as long
as the form is showing existing records. I can base the specific form on a
query that includes the fields from the main table that I want to repeat and
put the field names in the Control Source of the controls.
But what if we are creating new records? What do I have to do to make sure
controls on the specific form show information (from the main table) about
the record whose ID has just been set in the Activate Event?
In the case of a 1-to-many relationship, I understand this can be done by a
so-called autolookup query, but what in the case of a 1-to-1 relationship?
I hope you can give me some suggestions on these two questions.