R
Roland Alden
I have the following table structure in a database:
person table: myuid, some other data about the person
account table: myuid, uid of a person, credit-limit
credit card table: myuid, uid of an account, card number, other details
On top of this data I have a form/subform/subsubform situation as follows:
form is the base form for a person
subform is an account record which contains another datasheet subform for
rows of credit card records.
the subforms are linked up through the top level as you might expect.
When the user is filling out a form for a new person they visit fields in
the person form which cause a new person record to be created. When they go
to enter a credit card number for the first time there is no record in the
account table yet to provide a uid for linkage to the row that is about to
be created in the credit card table.
Right now, to solve this problem I have some code in a click handler for the
credit card number field. The code looks something like this:
Private Sub card_number_Click()
If Me.Parent.NewRecord Then
Me.Parent.[credit-limit].Value = 1000
Me.Parent.Recordset.Save
End If
End Sub
This seems to force the creation of a record in the account table such that
the linkage will work for the newly created card table row. It seemed as if
it was necessary to "dirty" the "pro forma" record by assigning a value to
credit-limit. Just doing the Recordset.Save was insufficient.
My question is, there has to be a better way, right? At best, if this code
is necessary it should be moved somewhere other than a click handler for one
field. I assume this is not an entirely uncommon problem and there is some
Access/VB idiom for such situations. In particular, if the very first thing
a person does when confronted with a blank form is click in the credit card
number box then the problem exists up the chain another level (and right now
bad things happen). I understand why, but don't know what the best way is of
dealing with such cases.
person table: myuid, some other data about the person
account table: myuid, uid of a person, credit-limit
credit card table: myuid, uid of an account, card number, other details
On top of this data I have a form/subform/subsubform situation as follows:
form is the base form for a person
subform is an account record which contains another datasheet subform for
rows of credit card records.
the subforms are linked up through the top level as you might expect.
When the user is filling out a form for a new person they visit fields in
the person form which cause a new person record to be created. When they go
to enter a credit card number for the first time there is no record in the
account table yet to provide a uid for linkage to the row that is about to
be created in the credit card table.
Right now, to solve this problem I have some code in a click handler for the
credit card number field. The code looks something like this:
Private Sub card_number_Click()
If Me.Parent.NewRecord Then
Me.Parent.[credit-limit].Value = 1000
Me.Parent.Recordset.Save
End If
End Sub
This seems to force the creation of a record in the account table such that
the linkage will work for the newly created card table row. It seemed as if
it was necessary to "dirty" the "pro forma" record by assigning a value to
credit-limit. Just doing the Recordset.Save was insufficient.
My question is, there has to be a better way, right? At best, if this code
is necessary it should be moved somewhere other than a click handler for one
field. I assume this is not an entirely uncommon problem and there is some
Access/VB idiom for such situations. In particular, if the very first thing
a person does when confronted with a blank form is click in the credit card
number box then the problem exists up the chain another level (and right now
bad things happen). I understand why, but don't know what the best way is of
dealing with such cases.