By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,863 Members | 838 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,863 IT Pros & Developers. It's quick & easy.

Required field in subform

P: n/a
I have a form frmViolations with a subform sfrmViolations. There is a
one-to-many relationship between the two.

On the subform I have a date field and a duration field. Both can be
blank but if the date field has a date then the duration field must be
filled in with some value.

Each violation has a violation description. I use a combo box to fill in
the description.

In the subform's table I tried making the duration required. When I do
that I am not able to add a violation description. A message on the
status bar says that the recordset cannot be updated. If I remove that
restriction, I can add a violation descrption to the Violation record.

So, my question is this: how can I make the duration field required in
the subform if there is a date in the date field. (I tried puttin some
code behind the Lost Focus event of the subform but to do avail.)

Any ideas will be appreciated.

Deborah

Nov 12 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Use a function in the form's BeforeUpdate event that will prevent the
record from being saved if all your required conditions are not met.
Example:

Private Sub Form_BeforeUpdate(Cancel As Integer)

Cancel = Not DataOK()

End Sub

Private Function DataOK() As Boolean

Dim strMsg As String

If Not IsNull(Me!ViolationDate) Then
If IsNull(Me!Duration) then
strMsg = "Duration"
End If
End If

If Len(strMsg)>0 then
MsgBox "Following fields are required:@" & strMsg & "@",vbCritical
Else
DataOK = True
End If

End Function

- --
MGFoster:::mgf
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBP49QbYechKqOuFEgEQKeIACg7uCKe7i9U5kKwc5LESii9G zya/cAn3JM
iDlAUeTBoTRS5WlyrywOSQFz
=zsga
-----END PGP SIGNATURE-----
Deborah V. Gardner wrote:
I have a form frmViolations with a subform sfrmViolations. There is a
one-to-many relationship between the two.

On the subform I have a date field and a duration field. Both can be
blank but if the date field has a date then the duration field must be
filled in with some value.

Each violation has a violation description. I use a combo box to fill in
the description.

In the subform's table I tried making the duration required. When I do
that I am not able to add a violation description. A message on the
status bar says that the recordset cannot be updated. If I remove that
restriction, I can add a violation descrption to the Violation record.

So, my question is this: how can I make the duration field required in
the subform if there is a date in the date field. (I tried puttin some
code behind the Lost Focus event of the subform but to do avail.)

Any ideas will be appreciated.

Deborah


Nov 12 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.