PDA

View Full Version : [SOLVED:] User Form - Restrict Entry



phendrena
10-20-2008, 07:11 AM
Hi,

Could someone give me some pointers on how to :-

1) "grey" out a text entry box based on the input from another field,
2) Force a value into a text entry field based on the input from another field,
3) Limit the choices in a combo box based on the input from another field

I appreciate these are a bit vague and i don't have any code as i've no idea where to start.

Thanks,

phendrena
10-24-2008, 05:01 AM
Does anyone have an suggestions for the above please?
Also how do I show or hide a text box/combo box/frame, based on the value of another box?

Thanks,

phendrena
10-27-2008, 06:59 AM
I really would appreciate any helps with these queries.
I'm getting desperate for the show/hide textbox etc solution.

Various fields start as hidden when the form is initilised, but i need to show fields depending on what is choosen from a menu in a combo box.
Try as i might i can't unhide the field :-

Starts Hidden :


Private Sub UserForm_Initialize()
frmDSTCallLog.txtScheme.Visible = False
frmDSTCallLog.lblScheme.Visible = False

Unhide? :


Private Sub Show()
If Me.cboSubject.Value = "Agency Amendment" Then
frmDSTCallLog.lblScheme.Visible = True
frmDSTCallLog.cboScheme.Visible = True
End Sub


Any suggestions?

Thanks,

CreganTur
10-27-2008, 09:23 AM
If this code is behind the currently open UserForm, then try using:




Private Sub Show()
If Me.cboSubject.Value = "Agency Amendment" Then
Me.lblScheme.Visible = True
Me.cboScheme.Visible = True
End If

End Sub


Use the Me keyword to refer to the currently open Form, instead of explicitly providing the form's name. That might clear up your issue.

mikerickson
10-27-2008, 12:43 PM
Your question is pretty generic.

1) The change routine for the "other field" could be written to control the
textbox's .Enabled property. For example

Private Sub ListBox1_Change()
With Me
.tbxSpouseName.Enabled = (.ListBox1.Value = "Married")
End With
End Sub
It could also control the .Visible property.

2)The "other field"'s Change event would be a place to do that.

Private Sub ListBox1_Change()
With Me
.tbxSpouseName.Enabled = (.ListBox1.Value = "Married")
If .ListBox1.Value = "Single" Then
.tbxEldestChildsName.Text = "<none>"
Else
With .tbxEldestChildsName
.Text = IIf(.Text = "<none>", vbNullString, .Text)
End With
End If
End With
End Sub

3)Again the Change Event is where I would do that.

Private Sub ListBox1_Change()
With Me
.tbxSpouseName.Enabled = (.ListBox1.Value = "Married")
If .ListBox1.Value = "Single" Then
.tbxEldestChildsName.Text = "<none>"
Else
With .tbxEldestChildsName
.Text = IIf(.Text = "<none>", vbNullString, .Text)
End With
End If
Dim memory As Long
If .ListBox1.Value = "Single" Or .ListBox1.Value = "Divorced" Then
With .cbxThanksgivingLocation
memory = .ListIndex
.Clear
.AddItem "My house"
.AddItem "Mom's house"
.AddItem "Grandma's house"
If memory < 3 Then .ListIndex = memory
End With
Else
With .cbxThanksgivingLocation
memory = .ListIndex
.List(0) = "Our house"
.AddItem "Spouse's Mom's house"
.AddItem "Spouse's Grandma's house"
.ListIndex = memory
End With
End If
End With
End Sub

phendrena
10-28-2008, 05:57 AM
Thanks for the replys they have helped me solve the problem.