Ensure field holds a value before continuing

N

Nico

I have a form which users enter requests, and I want to ensure that the field
UserID is filled in before they enter a close date (ClosedDate) in the form.

Private Sub ClosedDate_Enter()
If Forms![frmtrackingforms]![sfrmTrackingRequests]![UserID] Is Null Then
ActiveDocument.FormFields("UserID").Select
MsgBox "Please enter the user ID.", vbOKOnly
Else
End If
End Sub

I'm getting an error when I try this, saying that my variable is not
defined, but I'm not sure which bit needs to be defined?

Thanks for any and all help.
 
D

Douglas J. Steele

To refer to a control on a subform, you need to go through the subform
control on the parent form. Depending on how you added the form as a
subform, the name of the subform control may be different than the name of
the form being used as a subform. As well, in VBA, you use the IsNull()
function, not the Is Null keyword:

If IsNull(Forms![frmtrackingforms]![sfrmTrackingRequests].Form![UserID])
Then

If that doesn't work, double check the name of the subform control.
 
J

Jeff Boyce

Nico

It looks like you've chosen to allow the user to tab-into/enter the
[ClosedDate] control, then decide whether it's OK to do so.

Another approach might be to keep the [ClosedDate] control disabled until
the user has filled in a [UserID], then enable it, allowing data entry.

By the way, do you have any validation going on when the user enters a
[UserID]? Are you allowing them to enter anything they want?

Are the userIDs already known to you? If so, why not let the user SELECT
his/her userID (or name, or ...) from a combobox which lists possible (and
perhaps ONLY) userIDs (check the LimitToList property of a combobox)?

Good luck

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
N

Nico

That's a great idea. I got this far, but I'm stuck.

The field is disabled generally, but now whenever the field UserID is
clicked on it enables the ClosedDate field - whether or not a value has been
entered.

Any idea what I'm doing wrong?

Private Sub UserID_Enter()
If Not
IsNull(Forms![frmtrackingforms]![sfrmTrackingRequests].Form![UserID]) Then

Forms![frmtrackingforms]![sfrmTrackingRequests].Form![ClosedDate].Enabled =
True
Else
End If
End Sub

There's no validation on what user ID is entered this is to track IDs that
are being set up in a number of applications.

Thanks!

Jeff Boyce said:
Nico

It looks like you've chosen to allow the user to tab-into/enter the
[ClosedDate] control, then decide whether it's OK to do so.

Another approach might be to keep the [ClosedDate] control disabled until
the user has filled in a [UserID], then enable it, allowing data entry.

By the way, do you have any validation going on when the user enters a
[UserID]? Are you allowing them to enter anything they want?

Are the userIDs already known to you? If so, why not let the user SELECT
his/her userID (or name, or ...) from a combobox which lists possible (and
perhaps ONLY) userIDs (check the LimitToList property of a combobox)?

Good luck

Regards

Jeff Boyce
Microsoft Office/Access MVP


Nico said:
I have a form which users enter requests, and I want to ensure that the
field
UserID is filled in before they enter a close date (ClosedDate) in the
form.

Private Sub ClosedDate_Enter()
If Forms![frmtrackingforms]![sfrmTrackingRequests]![UserID] Is Null
Then
ActiveDocument.FormFields("UserID").Select
MsgBox "Please enter the user ID.", vbOKOnly
Else
End If
End Sub

I'm getting an error when I try this, saying that my variable is not
defined, but I'm not sure which bit needs to be defined?

Thanks for any and all help.
 
N

Nico

That's a great idea. I got this far, but I'm stuck.

The field is disabled generally, but now whenever the field UserID is
clicked on it enables the ClosedDate field - whether or not a value has been
entered.

Any idea what I'm doing wrong?

Private Sub UserID_Enter()
If Not
IsNull(Forms![frmtrackingforms]![sfrmTrackingRequests].Form![UserID]) Then

Forms![frmtrackingforms]![sfrmTrackingRequests].Form![ClosedDate].Enabled =
True
Else
End If
End Sub

There's no validation on what user ID is entered this is to track IDs that
are being set up in a number of applications.

Thanks!

Jeff Boyce said:
Nico

It looks like you've chosen to allow the user to tab-into/enter the
[ClosedDate] control, then decide whether it's OK to do so.

Another approach might be to keep the [ClosedDate] control disabled until
the user has filled in a [UserID], then enable it, allowing data entry.

By the way, do you have any validation going on when the user enters a
[UserID]? Are you allowing them to enter anything they want?

Are the userIDs already known to you? If so, why not let the user SELECT
his/her userID (or name, or ...) from a combobox which lists possible (and
perhaps ONLY) userIDs (check the LimitToList property of a combobox)?

Good luck

Regards

Jeff Boyce
Microsoft Office/Access MVP


Nico said:
I have a form which users enter requests, and I want to ensure that the
field
UserID is filled in before they enter a close date (ClosedDate) in the
form.

Private Sub ClosedDate_Enter()
If Forms![frmtrackingforms]![sfrmTrackingRequests]![UserID] Is Null
Then
ActiveDocument.FormFields("UserID").Select
MsgBox "Please enter the user ID.", vbOKOnly
Else
End If
End Sub

I'm getting an error when I try this, saying that my variable is not
defined, but I'm not sure which bit needs to be defined?

Thanks for any and all help.
 
J

Jeff Boyce

Another approach might be to check after the UserID control (a "field" is in
a table, a "control" is on a form or report) is updated (i.e. After Update),
then set the .Enabled property of [ClosedDate].

Regards

Jeff Boyce
Microsoft Office/Access MVP

Nico said:
That's a great idea. I got this far, but I'm stuck.

The field is disabled generally, but now whenever the field UserID is
clicked on it enables the ClosedDate field - whether or not a value has
been
entered.

Any idea what I'm doing wrong?

Private Sub UserID_Enter()
If Not
IsNull(Forms![frmtrackingforms]![sfrmTrackingRequests].Form![UserID]) Then

Forms![frmtrackingforms]![sfrmTrackingRequests].Form![ClosedDate].Enabled
=
True
Else
End If
End Sub

There's no validation on what user ID is entered this is to track IDs that
are being set up in a number of applications.

Thanks!

Jeff Boyce said:
Nico

It looks like you've chosen to allow the user to tab-into/enter the
[ClosedDate] control, then decide whether it's OK to do so.

Another approach might be to keep the [ClosedDate] control disabled until
the user has filled in a [UserID], then enable it, allowing data entry.

By the way, do you have any validation going on when the user enters a
[UserID]? Are you allowing them to enter anything they want?

Are the userIDs already known to you? If so, why not let the user SELECT
his/her userID (or name, or ...) from a combobox which lists possible
(and
perhaps ONLY) userIDs (check the LimitToList property of a combobox)?

Good luck

Regards

Jeff Boyce
Microsoft Office/Access MVP


Nico said:
I have a form which users enter requests, and I want to ensure that the
field
UserID is filled in before they enter a close date (ClosedDate) in the
form.

Private Sub ClosedDate_Enter()
If Forms![frmtrackingforms]![sfrmTrackingRequests]![UserID] Is Null
Then
ActiveDocument.FormFields("UserID").Select
MsgBox "Please enter the user ID.", vbOKOnly
Else
End If
End Sub

I'm getting an error when I try this, saying that my variable is not
defined, but I'm not sure which bit needs to be defined?

Thanks for any and all help.
 

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