requiring data in a field

G

Guest

Is there a way that I can require a user to enter data in a field only if
there is certain data in another field?

I have a field called Targeted Environment which is a combo box. I also
have another field called RFC#. I want to require the user to enter data
into the RFC field if the Targeted Environment field contains "Production".
I can think of this as an if statement to use if I was in Excel, but I am
building an Access database. Any help would be appreciated.

Rob
 
G

Guest

I would use the Form's Before Update event to do this.

If Me.[Targeted Environment] = "Production" And IsNull(Me.[RFC#]) Then
MsgBox "RFC# Must be filled in if Targeted Environment = Production", _
vbCritical + vbOkOnly, "Data Missing")
Cancel = True
Me.[RFC#].SetFocus
End If

One point. avoid using space and # in your naming. It means you have to
always use bracketing for Access or Jet to understand, and it is just poor
form. The general rule is for all naming, use only letters, numbers, and the
underscore _
 
G

Guest

Klatuu:

Thanks for the help and thanks for the advice in naming my fields.
Actually, I did not use this # in the name of the field, only for the label.
But, I have thought about using spaces and such in the field names. I will
definitely avoid that.

Thanks, again.

Rob

Klatuu said:
I would use the Form's Before Update event to do this.

If Me.[Targeted Environment] = "Production" And IsNull(Me.[RFC#]) Then
MsgBox "RFC# Must be filled in if Targeted Environment = Production", _
vbCritical + vbOkOnly, "Data Missing")
Cancel = True
Me.[RFC#].SetFocus
End If

One point. avoid using space and # in your naming. It means you have to
always use bracketing for Access or Jet to understand, and it is just poor
form. The general rule is for all naming, use only letters, numbers, and the
underscore _


Rob said:
Is there a way that I can require a user to enter data in a field only if
there is certain data in another field?

I have a field called Targeted Environment which is a combo box. I also
have another field called RFC#. I want to require the user to enter data
into the RFC field if the Targeted Environment field contains "Production".
I can think of this as an if statement to use if I was in Excel, but I am
building an Access database. Any help would be appreciated.

Rob
 
G

Guest

KlatuuA:

Here is your code with the correct fields. What am I doing wrong? If I try
to go to another record or a new record and the conditions are not met,
shouldn't the Msgbox data pop up. It isn't . There must be something in
this coding that is incorrect. Please help.

Klatuu said:
I would use the Form's Before Update event to do this.

If Me.[Targeted Environment] = "Production" And IsNull(Me.[RFC#]) Then
MsgBox "RFC# Must be filled in if Targeted Environment = Production", _
vbCritical + vbOkOnly, "Data Missing")
Cancel = True
Me.[RFC#].SetFocus
End If

One point. avoid using space and # in your naming. It means you have to
always use bracketing for Access or Jet to understand, and it is just poor
form. The general rule is for all naming, use only letters, numbers, and the
underscore _


Rob said:
Is there a way that I can require a user to enter data in a field only if
there is certain data in another field?

I have a field called Targeted Environment which is a combo box. I also
have another field called RFC#. I want to require the user to enter data
into the RFC field if the Targeted Environment field contains "Production".
I can think of this as an if statement to use if I was in Excel, but I am
building an Access database. Any help would be appreciated.

Rob
 
G

Guest

Klatuua:

Here is your code with the correct fields. What am I doing wrong? If I try
to go to another record or a new record and the conditions are not met,
shouldn't the Msgbox data pop up. It isn't . There must be something in
this coding that is incorrect. Please help.

Private Sub Form_BeforeUpdate(Cancel As Integer)

If (Me.[Staging] = "Production" And IsNull(Me.[RFCNumber])) Then
Msg "RFC # Must be filled in if Targeted Environment = Production"
vbCritical vbOKOnly, "Data Missing"
Cancel = True
Me.[RFCNumber].SetFocus
End If


End Sub






Klatuu said:
I would use the Form's Before Update event to do this.

If Me.[Targeted Environment] = "Production" And IsNull(Me.[RFC#]) Then
MsgBox "RFC# Must be filled in if Targeted Environment = Production", _
vbCritical + vbOkOnly, "Data Missing")
Cancel = True
Me.[RFC#].SetFocus
End If

One point. avoid using space and # in your naming. It means you have to
always use bracketing for Access or Jet to understand, and it is just poor
form. The general rule is for all naming, use only letters, numbers, and the
underscore _


Rob said:
Is there a way that I can require a user to enter data in a field only if
there is certain data in another field?

I have a field called Targeted Environment which is a combo box. I also
have another field called RFC#. I want to require the user to enter data
into the RFC field if the Targeted Environment field contains "Production".
I can think of this as an if statement to use if I was in Excel, but I am
building an Access database. Any help would be appreciated.

Rob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top