First, I am having a hard time with the syntax for a subform. I can't even get the code to realize I am on a subform.
Next, I have a main form frmAddDoc with a field txtTitle and a subform subfrmReference that loads from the main with an on_click event button. I have a field txtTitle in the subform that should be assigned the value txtTitle when the form is loaded from the on_click event of the main. Can someone please provide to me an example of code that would do this? I haven't done it in such a long time and my syntax is just not working.
Bottom line - txtTitle in the subform = txtTitle in the main form
Me!subfrmReferences.Form!subtxtTitle = Forms![frmAddNewDoc]![txtTitle].Value
Here is what I have so far:
Private Sub cmdReferencesComplete_Click()
With Me!subfrmReferences.Form
.Visible = False
End With
End Sub
Private Sub Form_GotFocus()
subtxtTitle.SetFocus
Me!subfrmReferences.Form!subtxtTitle = Forms![frmAddNewDoc]![txtTitle].Value
End Sub
Private Sub cmdAddAnother_Click()
Dim MyDB As Database, rcsReferences As Recordset
Set MyDB = DBEngine.Workspaces(0).Databases(0)
Set rcsReferences = MyDB.OpenRecordset("tblReferences")
rcsReferences.AddNew
rcsReferences![Title] = Forms![subfrmReferences]![subtxtTitle]
rcsReferences![Reference] = Forms![subfrmReference]![cboReference]
rcsReferences.Update
If Nz([subtxtTitle], "") = "" Or Nz([cboReference], "") = "" Then
MsgBox "You must complete all fields or click References Complete!", vbCritical, "Incomplete Record!"
Exit Sub
End If
MsgBox "This Reference has Added!", vbDefaultButton1, "Reference Added!"
subtxtTitle = ""
cboReference = ""
End Sub
Next, I have a main form frmAddDoc with a field txtTitle and a subform subfrmReference that loads from the main with an on_click event button. I have a field txtTitle in the subform that should be assigned the value txtTitle when the form is loaded from the on_click event of the main. Can someone please provide to me an example of code that would do this? I haven't done it in such a long time and my syntax is just not working.
Bottom line - txtTitle in the subform = txtTitle in the main form
Me!subfrmReferences.Form!subtxtTitle = Forms![frmAddNewDoc]![txtTitle].Value
Here is what I have so far:
Private Sub cmdReferencesComplete_Click()
With Me!subfrmReferences.Form
.Visible = False
End With
End Sub
Private Sub Form_GotFocus()
subtxtTitle.SetFocus
Me!subfrmReferences.Form!subtxtTitle = Forms![frmAddNewDoc]![txtTitle].Value
End Sub
Private Sub cmdAddAnother_Click()
Dim MyDB As Database, rcsReferences As Recordset
Set MyDB = DBEngine.Workspaces(0).Databases(0)
Set rcsReferences = MyDB.OpenRecordset("tblReferences")
rcsReferences.AddNew
rcsReferences![Title] = Forms![subfrmReferences]![subtxtTitle]
rcsReferences![Reference] = Forms![subfrmReference]![cboReference]
rcsReferences.Update
If Nz([subtxtTitle], "") = "" Or Nz([cboReference], "") = "" Then
MsgBox "You must complete all fields or click References Complete!", vbCritical, "Incomplete Record!"
Exit Sub
End If
MsgBox "This Reference has Added!", vbDefaultButton1, "Reference Added!"
subtxtTitle = ""
cboReference = ""
End Sub