VBA to clear textbox if the value of another combobox meets a certain criteria

d3stijl

New Member
Joined
Nov 25, 2014
Messages
5
Hi,

I have built an excel user form which captures data.

I have a combobox called 'ClosedCB' with the options 'yes' and 'no'.

If the value in ClosedCB is 'no' I would like it to clear another textbox called 'ReviewTB'.

Here is my code so far...

Private Sub SaveBTN_Click()


If Me.SprintRecord_RowNumber <> "" Then
Call SaveRecord(Me.SprintRecord_RowNumber.Value)
Else
Call SaveRecord

End If


End Sub
Function SaveRecord(Optional iRow As Long)


Dim ws As Worksheet
Set ws = Worksheets("WorkLog")
Const ForReading = 1, ForWriting = 2
Dim fso, f

Racf = Environ("USERNAME")
Name1 = Left(ThisWorkbook.Name, Len(ThisWorkbook.Name) - 5)

If NameCB.Value = "" Or SprintTB.Value = "" Or QCRefTB = "" Or ReviewDateTB = "" Then
MsgBox "You have not completed the required fields, please check and try again!", vbInformation + vbOKOnly, "Attention!"
Exit Function
Else

If
ClosedCB.Value = "Closed" Then DateRaisedTB.Value = ""

End If

If iRow = 0 Then
iRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row 'find first empty row on WS
End If

'inserts date into log
ws.Cells(iRow, 1).Value = "" & NameCB.Value
'inserts phone number into log
ws.Cells(iRow, 2).Value = "" & SprintTB.Value
'inserts Policy number into log
ws.Cells(iRow, 3).Value = "" & QCRefTB.Value
'inserts Campaign into log
ws.Cells(iRow, 4).Value = "" & DateRaisedTB.Value
'inserts Outcome into log
ws.Cells(iRow, 5).Value = "" & ReviewDateTB.Value
'inserts username into log
ws.Cells(iRow, 6).Value = "" & CheckBox1.Value
'inserts username into log
ws.Cells(iRow, 7).Value = "" & CheckBox2.Value
'inserts username into log
ws.Cells(iRow, 8).Value = "" & CheckBox3.Value
'inserts username into log
ws.Cells(iRow, 9).Value = "" & CheckBox4.Value
'inserts username into log
ws.Cells(iRow, 10).Value = "" & CheckBox5.Value
'inserts username into log
ws.Cells(iRow, 11).Value = "" & CheckBox6.Value
'inserts username into log
ws.Cells(iRow, 12).Value = "" & CheckBox7.Value
'inserts username into log
ws.Cells(iRow, 13).Value = "" & CheckBox8.Value
'inserts username into log
ws.Cells(iRow, 14).Value = "" & CheckBox9.Value
'inserts username into log
ws.Cells(iRow, 15).Value = "" & CheckBox10.Value
'inserts username into log
ws.Cells(iRow, 16).Value = "" & CheckBox11.Value
'inserts username into log
ws.Cells(iRow, 17).Value = "" & CheckBox12.Value
'inserts username into log
ws.Cells(iRow, 18).Value = "" & CheckBox13.Value
'inserts username into log
ws.Cells(iRow, 19).Value = "" & CheckBox14.Value
'inserts username into log
ws.Cells(iRow, 20).Value = "" & CheckBox15.Value
'inserts username into log
ws.Cells(iRow, 21).Value = "" & CheckBox16.Value
'inserts username into log
ws.Cells(iRow, 22).Value = "" & CheckBox17.Value
'inserts username into log
ws.Cells(iRow, 23).Value = "" & CheckBox18.Value
'inserts username into log
ws.Cells(iRow, 24).Value = "" & CheckBox19.Value
'Open Closed
ws.Cells(iRow, 25).Value = "" & Me.ClosedCB.Value
End If

'Saves the Workbook
ThisWorkbook.Save


MsgBox ("This Record has been logged.")
'hides the log call page

'Clears contents in Userform
Dim ctl As MSForms.Control


For Each ctl In Me.Controls
Select Case TypeName(ctl)
Case "TextBox"
ctl.Text = ""
Case "CheckBox", "OptionButton", "ToggleButton"
ctl.Value = False
Case "ComboBox", "ListBox"
ctl.ListIndex = -1
End Select
Next ctl


Me.Hide
MainMenu.Show

'brings back to main menu


End Function


Any help will be much appreciated :)
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

Forum statistics

Threads
1,216,212
Messages
6,129,531
Members
449,515
Latest member
lukaderanged

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top