Deny changing value in field, based on values of multiple fields

S

Sunflower

I have a form
Form: [frmWOEDIT]
with a drop down status selector
Dropdown field: [Status]

on my form [frmWOEDIT], I have a subform
Subform: [subfrmLABORDETAIL1]
with a text field and date field
Text Field: [Type)
Date Field: [DateDone]

My subform can have several rows (not always the same number) with
[Type], and the [DateDone] will be null until it is entered later.

MY PROBLEM:
I need a way to make sure when someone goes in and enters a
[DateDone], that they cannot change the [Status] on [frmWOEDIT] to
"Completed" unless ALL the rows in the [subfrmLABORDETAIL1] have date
entries in the [DateDone] field.

Any and all help in greatly appreciated
 
J

Jeanette Cunningham

Hi Sunflower,
DCount will help you here.
Use DCount to count how many rows in the subform have null date entries.
The date entries in the subform need to be saved before you use DCount, but
that should happen automatically when user moves out of the subform to click
the status on the main form.

VBA help explains how to use dcount.
You want to count how many records in the child table (with the matching ID
to the main form) have null for DateDone.
If the count is > 0 then you lock the drop down status selector.
You could put the DCount code on the enter event of the drop down so that it
always checks before users can choose a status.

Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 
S

Sunflower

Hi Sunflower,
DCount will help you here.
Use DCount to count how many rows in the subform have null date entries.
The date entries in the subform need to be saved before you use DCount, but
that should happen automatically when user moves out of the subform to click
the status on the main form.

VBA help explains how to use dcount.
You want to count how many records in the child table (with the matching ID
to the main form) have null for DateDone.
If the count is > 0 then you lock the drop down status selector.
You could put the DCount code on the enter event of the drop down so thatit
always checks before users can choose a status.

Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia




I have a form
Form: [frmWOEDIT]
with a drop down status selector
Dropdown field: [Status]
on my form [frmWOEDIT], I have a subform
Subform: [subfrmLABORDETAIL1]
with a text field and date field
Text Field: [Type)
Date Field: [DateDone]
My subform can have several rows (not always the same number) with
[Type], and the [DateDone] will be null until it is entered later.
MY PROBLEM:
I need a way to make sure when someone goes in and enters a
[DateDone], that they cannot change the [Status] on [frmWOEDIT] to
"Completed" unless ALL the rows in the [subfrmLABORDETAIL1] have date
entries in the [DateDone] field.
Any and all help in greatly appreciated- Hide quoted text -

- Show quoted text -

I am a newbi, so I wasnt sure how to code it the way you suggested...

Here is my failed attempt

In the "On Enter" event of the the Combo Box: [Status]
I put

IIf ( DCount ( [DateDone] , tblLABORDETAIL)>0 , "Completed",
[Status])


no such luck


Also,
Row Source of Combo Box: [Status] is
OPEN;Out On Proof;At Printer;Completed;On Hold;Cancelled;Waiting on
Someone Else

if that helps?



Any and all help in greatly appreciated
 
J

Jeanette Cunningham

This is quite challenging for a newbie!
You need to count how many entries in the subform have empty dates.
I am assuming that the subform has link master and child fields.

We need to get the criteria set up correctly.
So look for empty dates in the labour detail table where the link child
field matches the link master field.

Create a query based on the labour table. Use-->
--the foreign key that relates to the WOEDIT table,
--the primary key of the labour table,
--the DateDone field

In the criteria row, under DateDone type
Is Null

Save this query as qChkJobStatus

The DCount expression will be something like this untested air code-->
-------------------------
Private Sub Status_Enter()
Dim lngCount as Long
Dim strWhere as String

strWhere = "[FKeyName] = " & Me!FKeyName

lngCount = DCount("*", "qChkJobStatus", strCriteria)
Debug.Print lngCount

If lngCount > 0 Then
Me.Status.RowSource = "OPEN;Out On Proof;At Printer;On
Hold;Cancelled;Waiting on
Someone Else"

Else
Me.Status.RowSource = "OPEN;Out On Proof;At Printer;Completed;On
Hold;Cancelled;Waiting on
Someone Else"

End If
End Sub
------------------------------------
Replace FKeyName with the name of the field which links the subform to the
main form.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia



Hi Sunflower,
DCount will help you here.
Use DCount to count how many rows in the subform have null date entries.
The date entries in the subform need to be saved before you use DCount,
but
that should happen automatically when user moves out of the subform to
click
the status on the main form.

VBA help explains how to use dcount.
You want to count how many records in the child table (with the matching
ID
to the main form) have null for DateDone.
If the count is > 0 then you lock the drop down status selector.
You could put the DCount code on the enter event of the drop down so that
it
always checks before users can choose a status.

Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia




I have a form
Form: [frmWOEDIT]
with a drop down status selector
Dropdown field: [Status]
on my form [frmWOEDIT], I have a subform
Subform: [subfrmLABORDETAIL1]
with a text field and date field
Text Field: [Type)
Date Field: [DateDone]
My subform can have several rows (not always the same number) with
[Type], and the [DateDone] will be null until it is entered later.
MY PROBLEM:
I need a way to make sure when someone goes in and enters a
[DateDone], that they cannot change the [Status] on [frmWOEDIT] to
"Completed" unless ALL the rows in the [subfrmLABORDETAIL1] have date
entries in the [DateDone] field.
Any and all help in greatly appreciated- Hide quoted text -

- Show quoted text -

I am a newbi, so I wasnt sure how to code it the way you suggested...

Here is my failed attempt

In the "On Enter" event of the the Combo Box: [Status]
I put

IIf ( DCount ( [DateDone] , tblLABORDETAIL)>0 , "Completed",
[Status])


no such luck


Also,
Row Source of Combo Box: [Status] is
OPEN;Out On Proof;At Printer;Completed;On Hold;Cancelled;Waiting on
Someone Else

if that helps?



Any and all help in greatly appreciated
 
S

Sunflower

This is quite challenging for a newbie!
You need to count how many entries in the subform have empty dates.
I am assuming that the subform has link master and child fields.

We need to get the criteria set up correctly.
So look for empty dates in the labour detail table where the link child
field matches the link master field.

Create a query based on the labour table. Use-->
--the foreign key that relates to the WOEDIT table,
--the primary key of the labour table,
--the DateDone field

In the criteria row, under DateDone type
Is Null

Save this query as qChkJobStatus

The DCount expression will be something like this untested air code-->
-------------------------
Private Sub Status_Enter()
Dim lngCount as Long
Dim strWhere as String

strWhere = "[FKeyName] = " & Me!FKeyName

lngCount = DCount("*", "qChkJobStatus", strCriteria)
Debug.Print lngCount

If lngCount > 0 Then
Me.Status.RowSource = "OPEN;Out On Proof;At Printer;On
Hold;Cancelled;Waiting on
Someone Else"

Else
Me.Status.RowSource = "OPEN;Out On Proof;At Printer;Completed;On
Hold;Cancelled;Waiting on
Someone Else"

End If
End Sub
------------------------------------
Replace FKeyName with the name of the field which links the subform to the
main form.

Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia


Hi Sunflower,
DCount will help you here.
Use DCount to count how many rows in the subform have null date entries..
The date entries in the subform need to be saved before you use DCount,
but
that should happen automatically when user moves out of the subform to
click
the status on the main form.
VBA help explains how to use dcount.
You want to count how many records in the child table (with the matching
ID
to the main form) have null for DateDone.
If the count is > 0 then you lock the drop down status selector.
You could put the DCount code on the enter event of the drop down so that
it
always checks before users can choose a status.
Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
I have a form
Form: [frmWOEDIT]
with a drop down status selector
Dropdown field: [Status]
on my form [frmWOEDIT], I have a subform
Subform: [subfrmLABORDETAIL1]
with a text field and date field
Text Field: [Type)
Date Field: [DateDone]
My subform can have several rows (not always the same number) with
[Type], and the [DateDone] will be null until it is entered later.
MY PROBLEM:
I need a way to make sure when someone goes in and enters a
[DateDone], that they cannot change the [Status] on [frmWOEDIT] to
"Completed" unless ALL the rows in the [subfrmLABORDETAIL1] have date
entries in the [DateDone] field.
Any and all help in greatly appreciated- Hide quoted text -
- Show quoted text -

I am a newbi, so I wasnt sure how to code it the way you suggested...

Here is my failed attempt

In the "On Enter" event of the the Combo Box: [Status]
I put

IIf ( DCount ( [DateDone] , tblLABORDETAIL)>0 , "Completed",
[Status])

no such luck

Also,
Row Source of Combo Box: [Status] is
OPEN;Out On Proof;At Printer;Completed;On Hold;Cancelled;Waiting on
Someone Else

if that helps?

Any and all help in greatly appreciated- Hide quoted text -

- Show quoted text -

Another failed attempt...


The Subform [subfrmLABORDETAIL1] has link master and child fields....
Link Child Fields...WOID
Link Master Fields...WOID


I am not sure what you mean by Foreign key....
I created a query called qChkJobStatus
Here is the SQL:
SELECT tblWORKORDER.WOID, tblLABORDETAIL.WOID,
tblLABORDETAIL.DateDone
FROM tblWORKORDER INNER JOIN tblLABORDETAIL ON tblWORKORDER.WOID =
tblLABORDETAIL.WOID
WHERE (((tblLABORDETAIL.DateDone) Is Null));



I placed the following code In the "On Enter" event of the the Combo
Box: [Status]
------------------------------------
Private Sub Status_Enter()
Dim lngCount As Long
Dim strWhere As String


strWhere = "[WOID] = " & Me!WOID

lngCount = DCount("*", "qChkJobStatus", strCriteria)
Debug.Print lngCount

If lngCount < 0 Then
Me.Status.RowSource = "OPEN;Out On Proof;At Printer;On
Hold;Cancelled;Waiting on Someone Else"

Else
Me.Status.RowSource = "OPEN;Out On Proof;At Printer;Completed;On
Hold;Cancelled;Waiting on Someone Else"

End If
End Sub
------------------------------------
When I test, I do not get "Completed" as a option even when all
DateDone fields are not null.
When I change the <0 to >0, I then get the option of selecting
"Completed" even when DateDone fields are Null.


Any and all help is greatly appreciated.
 

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