Hello,
I've a table 'A' with a reference to another table 'B'. I've created a
form with A's fields, and a subform that displays B's fields, with a
link between them in the subform properties (Master: Bref, Child: ID).
This allows the user of the form to see and edit the fields in B, but
if I want to add a new row, I get the 'You can't assign a value to
this object' message (due to the link).
To get around this, and because I wanted to have a query functionality
as well for finding other rows in B for A to reference, I createa a
button 'Create/Choose' that opens up a the B form in a dialog window,
and in that form's Current function I save the last ID chosen by that
form in a global variable:
Private Sub Form_Current()
FormsModule.LastPropertyOwned571LTypeId = Me.ID
End Sub
So in the form for A you see this code:
Private Sub btnPropOwned_Click()
Dim fmname As String
fmname = "frmPropertyOwned571LType"
DoCmd.OpenForm fmname, WindowMode:=acDialog
Me.DeclarationPropertyOwnedRef =
FormsModule.LastPropertyOwned571LTypeId
Me.Refresh
End Sub
The problem with this is that ID is NULL when you try to create a new
row in the form. If I check for NULL, and then I don't set the
FormsModule.LastPropertyOwned571LTypeId then the new record value
never gets set. I can duplicate the code so that it sets it when the
record is closed, but that seems dangerous.
My questions are:
- Is there a better way to do this?
- Is there a way to get the current record from a form that has just
closed (i.e. avoid the global variable problem)
Thanks!
- is this the best way to