I am creating a userform to search and manage a list of contacts.
There is currently no search facility whilst I work on getting the data input/edit capability running as it should.
The first function I am trying to implement is decribed below.
The master linked accounts section is hidden unless the corresponding worksheets are selected where this information is applicable. When one of the worksheets that this information is relevant to is selected in the combobox, it should populate MLA option buttons.
I have two option buttons to the form 'MLA' called 'mstrYes' and 'mstrNo'. 'mstrNo' should be the default and I want to prevent the text box 'txt7' from appearing until mstrYes is selected, and if mstrNo is selected again, the text box should disappear again.
Also in relation to the text box 'txt7', how do I prevent the text within 'txt7' that appears automatically in 'Example1, Example2, Example3' mentioned previously from being cleared during the following procedure?
There is currently no search facility whilst I work on getting the data input/edit capability running as it should.
The first function I am trying to implement is decribed below.
The master linked accounts section is hidden unless the corresponding worksheets are selected where this information is applicable. When one of the worksheets that this information is relevant to is selected in the combobox, it should populate MLA option buttons.
I have two option buttons to the form 'MLA' called 'mstrYes' and 'mstrNo'. 'mstrNo' should be the default and I want to prevent the text box 'txt7' from appearing until mstrYes is selected, and if mstrNo is selected again, the text box should disappear again.
Also in relation to the text box 'txt7', how do I prevent the text within 'txt7' that appears automatically in 'Example1, Example2, Example3' mentioned previously from being cleared during the following procedure?
Code:
Dim ws As Worksheet
Private Sub cbContactType_Change()
Me.cmdbNew.Enabled = CBool(Me.cbContactType.ListIndex <> -1)
If Me.cbContactType.Enabled Then Set ws = Worksheets(cbContactType.Text)
Me.txt7.Visible = Not IsError(Application.Match(cbContactType.Text, Array("Housing Associations", "Landlords"), False))
Me.mstrAccounts.Visible = Me.txt7.Visible
Me.MLA.Visible = Me.txt7.Visible
End Sub
Private Sub iptSearch_Click()
Contacts.Hide
Unload Contacts
End Sub
'Private Sub cmdbChange_SpinUp()
' If Me.cbContactType.ListRows.Count < 1 Then Exit Sub
' If CurrentRow > 1 Then
' CurrentRow = CurrentRow - 1
' UpdatecmdbChange
' End If
'End Sub
'Private Sub cmdbChange_SpinDown()
' If CurrentRow = Me.cbContactType.ListRows.Count Then Exit Sub
' If CurrentRow < Me.cbContactType.ListRows.Count Then
' CurrentRow = CurrentRow + 1
' UpdatecmdbChange
' End If
'End Sub
'Private Sub UpdatePositionCaption()
' dtaRow.Caption = CurrentRow & " of " & Me.cbContactType.ListRows.Count
'End Sub
Private Sub UserForm_Initialize()
Me.cbContactType.List = Array("Council Contacts", "Local Contacts", "Housing Associations", "Landlords", "Letting and Selling Agents", "Developers", "Employers")
Me.cmdbNew.Enabled = False
Me.txt7.Visible = False
Me.mstrAccounts.Visible = False
Me.MLA.Visible = False
End Sub
Private Sub cmdbNew_Click()
Dim cNum As Integer, X As Integer
Dim nextrow As Long
nextrow = ws.Cells(ws.Rows.Count, "B").End(xlUp).Row
If Len(ws.Cells(1, 2).Value) > 0 Then nextrow = nextrow + 1
cNum = 7
Dim AlignLeft As Boolean
For X = 1 To cNum
AlingLeft = CBool(X = 1 Or X = 7)
With ws.Cells(nextrow, X + 1)
.Value = Me.Controls("txt" & X).Value
.EntireColumn.AutoFit
.HorizontalAlignment = IIf(X = 1, xlLeft, xlCenter)
.VerticalAlignment = xlCenter
With .Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 10
End With
End With
Me.Controls("txt" & X).Text = ""
Next
MsgBox "Contact added to " & ws.Name, 64, "Contact Added"
End Sub
Private Sub cmdbClose_Click()
Unload Me
End Sub