Resetting Event Procedures for a New Record in a Form

Pooks_35

Registered User.
Local time
Today, 00:59
Joined
Mar 14, 2013
Messages
54
I have the following Event Procedures in a form:

Private Sub PrimaryDisability_Change()
Select Case Me.PrimaryDisability
Case "Other (Specify)"
PrimaryOther.Visible = True
Case Else
PrimaryOther.Visible = False
End Select
End Sub

Private Sub SecondaryDisabilityYN_Click()
Me.SecondaryDisability.Visible = Me.SecondaryDisabilityYN = True
Me.CauseofSecondary.Visible = Me.SecondaryDisability.Visible = True
End Sub

My problem is that when I go to a new record, the fields that I want hidden in the new record unless they meet the criteria are still visible. I have looked all over online and in books to determine the code I use or whatever I need to do to make the field invisible in the new record and only to appear in each record if it meets the criteria. Please help as I've spent a lot of time on researching this already! Thanks in advance for any help.
 
Thanks for the suggestion, but if I try to create this under On Current I can't use End If or End Sub to complete the code. It keeps coming back with errors.:banghead:
 
What does the code look like when that happens?
 
Private Sub Form_Current()
If Me.PrimaryDisability = "Other (Specify)" Then
Me.PrimaryOther.Visible = True
Else
Me.PrimaryOther.Visible = False
If Me.SecondaryDisability.Visible = Me.SecondaryDisabilityYN = True Then
Me.CauseofSecondary.Visible = True
End If
End Sub

Private Sub PrimaryDisability_Update()
Select Case Me.PrimaryDisability
Case "Other (Specify)"
PrimaryOther.Visible = True
Case Else
PrimaryOther.Visible = False
End Select
End Sub

Private Sub SecondaryDisabilityYN_Click()
Me.SecondaryDisability.Visible = Me.SecondaryDisabilityYN = True
Me.CauseofSecondary.Visible = Me.SecondaryDisability.Visible = True
End Sub

It doesn't like End If and it doesn't like End Sub.
 
No, you've got two "If" statements but only one "End If".
 
Great! Thank you, that fixed the Primary Disability, however, the Secondary Disability continues to show in the new record. I'm guessing I need to change something within the code to make that work as well. Any suggestions would be great! I really appreciate your help!
 
Thanks! I just figured it out, but I couldn't have done it without your help! Thank you!:)
 
Wouldn't those 2 lines work added to the current event code?
 
Ah, typing at the same time. Glad you got it sorted out!
 
HI pbaldy,
I spoke to soon, everything is working, however, now when I choose Other (Specify) in the PrimaryDisability field, the PrimaryOther no longer shows up, I can't figure what I did wrong with the codes! Any thoughts?:banghead:

Private Sub Form_Current()
If Me.PrimaryDisability = "Other (Specify)" Then
Me.PrimaryOther.Visible = True
Else
Me.PrimaryOther.Visible = False
End If
If Me.SecondaryDisabilityYN = True Then
Me.SecondaryDisability.Visible = True
Me.CauseofSecondary.Visible = True
Else
Me.SecondaryDisability.Visible = False
Me.CauseofSecondary.Visible = False
End If
End Sub

Private Sub PrimaryDisability_Update()
Select Case Me.PrimaryDisability
Case "Other (Specify)"
PrimaryOther.Visible = True
Case Else
PrimaryOther.Visible = False
End Select
End Sub

Private Sub SecondaryDisabilityYN_Click()
Me.SecondaryDisability.Visible = Me.SecondaryDisabilityYN = True
Me.CauseofSecondary.Visible = Me.SecondaryDisability.Visible = True
End Sub
 
Found it, I didn't have AfterUpdate, just Update! Now it works...again, thank you!
 
just out of interest, it's a personal taste, but rather than hide things, I prefer to make them grayed out.

instead of setting visible=no, just set enabled=no

enabled and locked work together

enabled=no, locked=no = grayed
enabled=yes, locked=no = normal
enabled=no, locked=yes = control visible, but not interactive
enabled=yes, locked=yes = control active, but not editable
 

Users who are viewing this thread

Back
Top Bottom