Hi,
I am trying to build a chemical lab result database and have have some difficulties in getting my form for result input to work. Here is the situation (somewhat simplified):
I have three tables : Articles<-on-to-many->Specifications<-one-to-many->SamplingPlan
All tables have corresponding forms: frmArticle (single form), frmSpecification(cont.form), frmSamplingPlan(cont.form)
The fields keeping the relationships together are:
kp_ArticleID <-> kf_ArticleID/kp_SpecifiationID <-> kf_SpecificationID
I have a frmArticles with the frmSpecifications as subform. In the frmSpecifications subform I have a button that opens a popup window with the following VBA code:
Private Sub SamplingPlan_Click()
Dim strWC As String
strWC = "kf_SpecificationID = " & Me!kp_SpecificationID
DoCmd.OpenForm "frmSamplingPlan", , , strWC, acFormEdit, acDialog, Me!kp_SpecificationID
End Sub
In order to get the relationship field values set I have the following code on frmSamplingPlan (popup window) load:
Private Sub Form_Load()
DoCmd.MoveSize (1440 * 0.78), (1440 * 1.8)
Me!kf_SpecificationID.DefaultValue = """" & Me.OpenArgs & """"
Me.AllowAdditions = False
End Sub
I also add AllowAdditions = false in order to hide the (new) record at the bottom of the continuous form.
I then have the following code to be able to add records:
Private Sub AddNewRecord_Click()
Dim rst As DAO.Recordset
Me.AllowAdditions = True
Set rst = Me.Recordset
rst.AddNew
rst.Update
Me.Description.SetFocus
Me.AllowAdditions = False
End Sub
The problem with this is that the defaultvalue is removed and the relationship to the new records disappears. It is the rst.update that removes the defaultvalue.
Anyone with an idea on how to solve this?
//Triplee23