Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sub form Criteria question 2

Status
Not open for further replies.

iuianj07

Programmer
Sep 25, 2009
293
US
Hello guys,

I have a main form frmJob_TrackingAll with a subform,(set as continuous form) and linked via Situs_ID that acts as a tracking form for each status/phase of each parent record.

on the subform I have a combobox that lists the different status/phase for each parent record, and I also have a textbox (StatusTime) field where users will enter how many hours they spent in for that specific child record (status/phase). What we need to do though is disable StatusTime so users can't have the mistake in entering hours on a status that shouldn't have any hours spent on it.

I wrote this code:

Code:
Private Sub InStChID_AfterUpdate()
If Me.InStChID = 5 Then
Me.StatusTime.Enabled = False
Else
If Me.InStChID = 7 Then
Me.StatusTime.Enabled = False
Else
If Me.InStChID = 9 Then
Me.StatusTime.Enabled = False
Else
If Me.InStChID = 13 Then
Me.StatusTime.Enabled = False
Else
If Me.StatusTime = 15 Then
Me.StatusTime.Enabled = False
Else
Me.StatusTime.Enabled = True
End If
End If
End If
End If
End If

End Sub

InStChID is the dropdown name (which lists down all status)

What happens with this code though is once I choose a status from above (5,7,9,13) on the dropdown box, it disables all StatusTime textbox for all records in the subform...

As I am not that great in writing code (my biggest frustration) Is there a way that it only disables the child record that actually has the status above?

Any help is greatly appreciated.

Thank you
 
A control on a continuous form is either enabled or disabled for all records. You could use code in the On Current event or the form to enable or disable the control.

Your code (if it even worked) could be written simpler as:
Code:
Private Sub InStChID_AfterUpdate()
Select Case Me.InStChID 
    Case 5, 7, 9, 13, 15
        Me.StatusTime.Enabled = False
    Case Else
        Me.StatusTime.Enabled = True
End Select

Duane
Hook'D on Access
MS Access MVP
 
In the conditional formatting, I think you have to choose "expression is". Do not think there is a way to choose "field value is"

Expression is:
[inSTCHID] = 5 or [instchiid] = 9 or .... = 13
 
Hello dhookom and MajP,

I tried to put the code on the On Current event of the sub-form, and also used the simpler code by dhookom...

It looks like it does lock (I changed it from .Enabled to .Locked)
whenever I choose a status from above, but the problem is for some reason it takes a couple of seconds for the StatusTime to lock the field instead of locking it right after I choose a status at the dropdown? This could be an issue wherein the user will just simply choose the status then enter StatusTime right away? From my observation, whenever I choose a status then saved the record (the one on the left side) then that's the time I think it actually locks the field?

Idk if I'm just seeing things or being weird again... but is this how it should be expected? Or are there any other ways?

Thank you both again
 
hello dhookom,

can you please explain to me what you mean that I should modify the code to set StatusTime control/field to either Null or 0?

can you please provide a sample code? I've been trying to look for what I should code to set it up, but unsuccesful?

Thank you again dhookom

 
From my previous example since you haven't provided your code:
Code:
Private Sub InStChID_AfterUpdate()
Select Case Me.InStChID 
    Case 5, 7, 9, 13, 15
        Me.StatusTime.Enabled = False
[red]        Me.StatusTime = 0[/red]
    Case Else
        Me.StatusTime.Enabled = True
End Select

Duane
Hook'D on Access
MS Access MVP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top