Solved Display text field on Main Form after text entered on SubForm

Mick3911

Registered User.
Local time
Today, 03:24
Joined
Jul 31, 2018
Messages
40
I have a main form ‘frmUpdateTraining’ and a sub form ‘subfrmTrainingTimes’ which is a continuous form.

On the main form there are (amongst others) 2 fields ‘DateCompleted’ and ‘TrainedBy’

On the sub form there a 3 text fields ‘TrainingDate’, ‘StartTime’ and ‘EndTime’.

When a user enters a time in the ‘StartTime’ text field, I would like the text fields ‘DateCompleted’ and ‘TrainedBy’ on the main form to either become visible or enabled.

The code that I have used is in the BeforeUpdateEvent is

Code:
If IsNull(Me.StartTime) Then
Me.([frmUpdateTraining]![DateCompleted]).Visible = False
Me.([frmUpdateTraining]![TrainedBy]) = False
Else
Me.([frmUpdateTraining]![DateCompleted]).Visible = False
Me.([frmUpdateTraining]![TrainedBy]) = False
End If

I am struggling with my coding to achieve this; can someone please help.
 
You need to reference the subform's parent:
Code:
If IsNull(Me.StartTime) Then
    Me.Parent![DateCompleted].Visible = False
    Me.Parent[TrainedBy] = False
Else
    Me.Parent![DateCompleted].Visible = False
    Me.Parent![TrainedBy] = False
End If
And I would advide you to move the code to the AfterUpdate event of the StartTime textbox.

Cheers,
Vlad
 
😊 I just copied what the OP had, I should have looked closer....
 
this time i will agree with post#5.

if the subform is holding multiple "training modules (course)", then
the main form should GoTo correct record related (master?) record
before the two fields should be shown/hidden.
 
The training times relate to one training item/course. So an employee could receive just one training session say on the 1st or could receive multiple training sessions say on the 3rd, 10th, 11th and 21st.
 
My code should have read

If IsNull(Me.StartTime) Then
Me.([frmUpdateTraining]![DateCompleted]).Visible = False
Me.([frmUpdateTraining]![TrainedBy]).Visible = False
Else
Me.([frmUpdateTraining]![DateCompleted]).Visible = True
Me.([frmUpdateTraining]![TrainedBy]).Visible = True
End If
 
Last edited:
So can you try what I suggested... :)?
Cheers,
 
The training times relate to one training item/course. So an employee could receive just one training session say on the 1st or could receive multiple training sessions say on the 3rd, 10th, 11th and 21st.
then you should put the TrainedBy and DateCompleted on same table (subform).
 
But training won't be completed until the trainer is satisfied that the trainee have grasped the training which could take just one training session or more.
 
When I have completed the StartTime textbox I get a Run-time error '438', Object doesn't support this property or method.

Is this because the subform is a continuous form?
 
Could you upload a small sample with just the two forms and the table with some dummy data to show the issue?

Based on your comments in post # 8 and 12 I think you are best to move the code to the Current event of the main form and use a Dmax on the training date from the subforms record source. Or you could create a totals query grouped by the trainee ID with Max on the TrainingDate and having Not Is Null in the Starting time then use a dCount > 0 to make the two textboxes visible (and use dlookup in that totals query as the control source for the date completed).

Regarding your error maybe try this:
Code:
If IsNull(Me.StartTime) Then
    Me.Parent.Form.Controls("DateCompleted").Visible = False
    Me.Parent.Form.Controls("TrainedBy").Visible = False
Else
    Me.Parent.Form.Controls("DateCompleted").Visible = True
    Me.Parent.Form.Controls("TrainedBy").Visible = True
End If
Cheers,
 
I have got this to work how I want by setting the visible properties for the ‘DateCompleted’ and ‘TrainedBy’ textboxes on the main form to No and then used this code in ‘StartTime’ After Update property on the subform


Code:
Private Sub StartTime_AfterUpdate()
If Not IsNull([StartTime]) Then
Me.Parent.[Date_Taken].Visible = True
Me.Parent.[Trained_By].Visible = True
End If
End Sub

Gents, I would like to thank you for your time and effort in providing your help and suggestions, much appreciated. (I will no doubt return when I am close to throwing the PC out of the window when I come across another problem :)).
 
‘StartTime’ After Update property on the subform
what if i go back to the record and blank the starttime again, still the 2 fields are showing?
 
Yes, but you can only close the form by a command button which checks if relevant fields are completed.
 

Users who are viewing this thread

Back
Top Bottom