S
Sprinks
For a Chemical Inventory database, there are the tables:
Containers A bottle, jar, or other container of
"stuff", and its qty and unit
Substances A chemical, its CAS Registry #s, and Hazard
Class
ContainerSubstances The % of each Substance in a Container
There is a Container main form with a ContainerSubstance subform. Since
there are multiple fields in Substances, if the Substance does not exist,
rather than using the NotInList event, I've provided a "New" button which
opens the Substance form in Add and Dialog modes.
A form BeforeUpdate procedure ensures that all required fields are filled:
Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo Err_Handler
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.Tag = "R" Then
If Nz(ctl) = 0 Then
Beep
MsgBox ctl.ControlSource & " is a required field. Please
enter a value."
ctl.SetFocus
Cancel = True
Exit For
End If
End If
Next ctl
Err_Exit:
Exit Sub
Err_Handler:
Select Case Err.Number
Case Else
MsgBox Err.Description
Resume Err_Exit
End Select
End Sub
I've provided a "Save" button, with which I wish to requery the previous
form's combo box to include the new record, select the new value from the
combo box, and close the Substance form IF all of the fields are validated by
the BeforeUpdate procedure.
If the user has entered nothing, I want to simply close the form,
redundantly doing what could also be done by a "Cancel" button.
The following code, in combination with the BeforeUpdate displays a message
correctly for blank required fields, but then closes the form regardless, not
letting the user update the missing field(s).
Private Sub cmdSave_Click()
On Error GoTo Err_cmdSave_Click
If Not Me.NewRecord Then
With Forms![Containers].[sbfContainerSubstances].Form![cboSubstanceID]
.Requery
.Value = Me![txtSubstanceID]
End With
End If
DoCmd.Close
Exit_cmdSave_Click:
Exit Sub
Err_cmdSave_Click:
MsgBox Err.Description
Resume Exit_cmdSave_Click
End Sub
How can I avoid this? Can I test if BeforeUpdate has set Cancel to True
within the scope of the Save event? Or is there an easier way?
Thank you,
Sprinks
Containers A bottle, jar, or other container of
"stuff", and its qty and unit
Substances A chemical, its CAS Registry #s, and Hazard
Class
ContainerSubstances The % of each Substance in a Container
There is a Container main form with a ContainerSubstance subform. Since
there are multiple fields in Substances, if the Substance does not exist,
rather than using the NotInList event, I've provided a "New" button which
opens the Substance form in Add and Dialog modes.
A form BeforeUpdate procedure ensures that all required fields are filled:
Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo Err_Handler
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.Tag = "R" Then
If Nz(ctl) = 0 Then
Beep
MsgBox ctl.ControlSource & " is a required field. Please
enter a value."
ctl.SetFocus
Cancel = True
Exit For
End If
End If
Next ctl
Err_Exit:
Exit Sub
Err_Handler:
Select Case Err.Number
Case Else
MsgBox Err.Description
Resume Err_Exit
End Select
End Sub
I've provided a "Save" button, with which I wish to requery the previous
form's combo box to include the new record, select the new value from the
combo box, and close the Substance form IF all of the fields are validated by
the BeforeUpdate procedure.
If the user has entered nothing, I want to simply close the form,
redundantly doing what could also be done by a "Cancel" button.
The following code, in combination with the BeforeUpdate displays a message
correctly for blank required fields, but then closes the form regardless, not
letting the user update the missing field(s).
Private Sub cmdSave_Click()
On Error GoTo Err_cmdSave_Click
If Not Me.NewRecord Then
With Forms![Containers].[sbfContainerSubstances].Form![cboSubstanceID]
.Requery
.Value = Me![txtSubstanceID]
End With
End If
DoCmd.Close
Exit_cmdSave_Click:
Exit Sub
Err_cmdSave_Click:
MsgBox Err.Description
Resume Exit_cmdSave_Click
End Sub
How can I avoid this? Can I test if BeforeUpdate has set Cancel to True
within the scope of the Save event? Or is there an easier way?
Thank you,
Sprinks