Hi!
My form respectively subform has a couple of problems related to the recordset as it is available in VBA.
The mainform contains material data, the subform contains the components of that material and a quantity, while the components are materials themselves. The subform's control source is an SQL statement created by the query builder.
Everything worked fine before i replaced the material-selecting combobox in the continuous subform by a textbox and a button. That button leads to another (dialog) form with some filtering options, which in turn returns the number of the selected material. This material gets inserted into the textbox. To this point it works fine.
But when i enter a quantity before i selected a Material, i get an error message after selecting the Material: This Action was Cancelled by an Associated Object. This happens while executing the following VBA Code on click of the material selection button (exact position commented in code):
I've found the following Microsoft KB Article: support.microsoft.com/kb/189851/en-us (sorry, forum doesn't allow me to post links yet). It didn't help, yet i didn't understand everything.
In their example code they use:
I assume this is the relevant part, but i have no DataControl (what's that?) and neither found an UpdateControls method in the subform object.
The second error, "no current recordset", occures when i edit an existing component line in the subform that has been added right before (also using the same event and code as mentioned above). If i close the form after adding the component and open it again, it's no problem.
Thanks for any hints!
whisp
My form respectively subform has a couple of problems related to the recordset as it is available in VBA.
The mainform contains material data, the subform contains the components of that material and a quantity, while the components are materials themselves. The subform's control source is an SQL statement created by the query builder.
Everything worked fine before i replaced the material-selecting combobox in the continuous subform by a textbox and a button. That button leads to another (dialog) form with some filtering options, which in turn returns the number of the selected material. This material gets inserted into the textbox. To this point it works fine.
But when i enter a quantity before i selected a Material, i get an error message after selecting the Material: This Action was Cancelled by an Associated Object. This happens while executing the following VBA Code on click of the material selection button (exact position commented in code):
Code:
Private Sub cbuSelectComponent_Click()
' Select component
Dim SQL As String
Dim rs As Recordset
DoCmd.OpenForm "Material Selector Dialog", , , , , acDialog, "Dialog"
If GLB_selected_mat = -1 Then 'cancel
Exit Sub
End If
If GLB_selected_mat = -100 Then 'delete
Set rs = Me.Form.Recordset
rs.Delete
Exit Sub
End If
Set rs = Me.Form.Recordset
If Me.Form.NewRecord Then
rs.AddNew '*** Here the error message pops up, but only when quantity set before material ***
rs![Parent Component] = Forms![Materials].[Material ID]
rs![Materials Components.Sub Component] = GLB_selected_mat
rs.Update
Else
rs.Edit
rs![Materials Components.Sub Component] = GLB_selected_mat
rs.Update
End If
Me.Parent.Refresh
End Sub
In their example code they use:
Code:
' Restore text box value to the original record contents
' in this case, that is NULL
datDataCtl.UpdateControls
The second error, "no current recordset", occures when i edit an existing component line in the subform that has been added right before (also using the same event and code as mentioned above). If i close the form after adding the component and open it again, it's no problem.
Thanks for any hints!
whisp