S
sheetsumon
How do I pass a global variable defined by the first form to set the
RecordSource of the second form?
I have two forms "MasterForm1" and "MasterForm2." Both of these are linked
to the same table "MasterTable."
The first form's 'Data Entry' property is set to "YES" since it always
accepts new data.
The purpose of the second form is to continue entering data for the same row
in the MasterTable. Therefore, I'm trying to pass the current record number
(in this case, 'masterEntryNo'...Primary Key, AutoNumber) as a global
variable (as defined in a separate VB Module) to dynamically set the
RecordSource for the second form.
I tried the following,
MasterForm1 code:
Private Sub NextForm_Click()
Dim stDocName As String
Dim stLinkCriteria As String
lastRecord = Me.masterEntryNo.Value
prodCategory = Me.prodCatID.Value
stDocName = "MasterForm2"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End Sub
MasterForm2 code:
Private Sub MasterForm2_OnLoad()
Dim strSQL As String
Dim strSQL2 As String
strSQL = "SELECT * FROM MasterTable WHERE masterEntryNo = " & lastRecord
strSQL2 = "SELECT productName, prodNameID FROM ProductName WHERE
prodCatID = " & prodCategory
Me.RecordSource = strSQL
Me.productName.RowSource = strSQL2
End Sub
The MasterForm2_OnLoad() doesn't do anything to the RecordSource, no matter
what I try. (My form shows up with #Name? all over it). If I put the above
code into a button on MasterForm2, it seems to set the RecordSource for the
form, but it's always for the next row in the table!?
Can anyone help with this?
RecordSource of the second form?
I have two forms "MasterForm1" and "MasterForm2." Both of these are linked
to the same table "MasterTable."
The first form's 'Data Entry' property is set to "YES" since it always
accepts new data.
The purpose of the second form is to continue entering data for the same row
in the MasterTable. Therefore, I'm trying to pass the current record number
(in this case, 'masterEntryNo'...Primary Key, AutoNumber) as a global
variable (as defined in a separate VB Module) to dynamically set the
RecordSource for the second form.
I tried the following,
MasterForm1 code:
Private Sub NextForm_Click()
Dim stDocName As String
Dim stLinkCriteria As String
lastRecord = Me.masterEntryNo.Value
prodCategory = Me.prodCatID.Value
stDocName = "MasterForm2"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End Sub
MasterForm2 code:
Private Sub MasterForm2_OnLoad()
Dim strSQL As String
Dim strSQL2 As String
strSQL = "SELECT * FROM MasterTable WHERE masterEntryNo = " & lastRecord
strSQL2 = "SELECT productName, prodNameID FROM ProductName WHERE
prodCatID = " & prodCategory
Me.RecordSource = strSQL
Me.productName.RowSource = strSQL2
End Sub
The MasterForm2_OnLoad() doesn't do anything to the RecordSource, no matter
what I try. (My form shows up with #Name? all over it). If I put the above
code into a button on MasterForm2, it seems to set the RecordSource for the
form, but it's always for the next row in the table!?
Can anyone help with this?