Hi guys,
I've built a form that lets users enter generic details for a purchase order (Customer name, description etc). Within this form is a continuous sub-form where product lines are entered.
On clicking the Save & Close button I'd like to check for mandatory fields. I have managed to get this working successfully for the fields on the main form. I also have it working for the fields on the sub-form, however, when I enter a product line in the continuous form the next row is displayed and I cannot exit the form as it picks up the blank fields.
How can I get around this? I'd like for the main form to have at least ONE record entered into the sub-form before a user is allowed to close it.
Thanks very much
David
-------------
edit
Here is the code I'm using to check the fields:
I've built a form that lets users enter generic details for a purchase order (Customer name, description etc). Within this form is a continuous sub-form where product lines are entered.
On clicking the Save & Close button I'd like to check for mandatory fields. I have managed to get this working successfully for the fields on the main form. I also have it working for the fields on the sub-form, however, when I enter a product line in the continuous form the next row is displayed and I cannot exit the form as it picks up the blank fields.
How can I get around this? I'd like for the main form to have at least ONE record entered into the sub-form before a user is allowed to close it.
Thanks very much
David
-------------
edit
Here is the code I'm using to check the fields:
Code:
Private Sub btncloseform_Click()
Dim txtMessage As String
On Error GoTo Err_btnSave_Click
' init error message
txtMessage = ""
' Check fields in reverse order to set focus to the first
If Not Len(Nz(Me.Customer)) > 0 Then
txtMessage = "'Customer' cannot be left blank" & vbCrLf
Me.lblmandatory.Visible = True
Me.Customer.SetFocus
Else
Me.Customer.BackColor = vbWhite
End If
If Not Len(Nz(Me.EventDescription)) > 0 Then
txtMessage = "'Event Description' cannot be left blank" & vbCrLf
Me.lblmandatory1.Visible = True
Me.EventDescription.SetFocus
Else
Me.EventDescription.BackColor = vbWhite
End If
If Not Len(Nz(Forms![frm_consumption]![Child15].Form![ProdID])) > 0 Then
txtMessage = "Please enter some product lines" & vbCrLf
Forms![frm_consumption]![Child15].Form![lblmandatory2].Visible = True
'Forms![frm_consumption]![Child15].Form![ProdID].SetFocus
Else
Me.EventDescription.BackColor = vbWhite
End If
If Not Len(Nz(Forms![frm_consumption]![Child15].Form![TransQty])) = 0 Then
txtMessage = "Please enter a Quantity" & vbCrLf
Forms![frm_consumption]![Child15].Form![lblmandatory3].Visible = True
'Forms![frm_consumption]![Child15].Form![ProdID].SetFocus
Else
Me.EventDescription.BackColor = vbWhite
End If
If Not Len(Nz(Forms![frm_consumption]![Child15].Form![CostPerItem])) = 0 Then
txtMessage = "Please enter a Cost Per Item" & vbCrLf
Forms![frm_consumption]![Child15].Form![lblmandatory4].Visible = True
'Forms![frm_consumption]![Child15].Form![ProdID].SetFocus
Else
Me.EventDescription.BackColor = vbWhite
End If
' Check error found
If Len(txtMessage) > 0 Then
MsgBox txtMessage
Exit Sub
End If
DoCmd.Close
Exit_btnSave_Click:
Exit Sub
Err_btnSave_Click:
MsgBox Err.Description
Resume Exit_btnSave_Click
End Sub