checkbox if sentence

mahyr

New Member
Joined
Oct 5, 2017
Messages
5
Private Sub cbAge_Click()
Me.cboAge.Enabled = Me.cbAge
End Sub


Private Sub cbGender_Click()
Me.cboGender.Enabled = Me.cbGender
End Sub


Private Sub cbMode_Click()
Me.cboMode.Enabled = Me.cbMode
End Sub


Private Sub cbName_Click()
Me.textbox_name.Enabled = Me.cbName
End Sub




Private Sub cbSurname_Click()
Me.textbox_surname.Enabled = Me.cbSurname
End Sub


Private Sub cmdbutton_add_Click()


Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Sheet1")


'avalin radif khali dar paigah dadei ro peida kon
'find first empty row in database
iRow = ws.Cells.Find(What:="*", _
SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, _
LookIn:=xlValues).Row + 1


'check for a name number
If (UserForm1.cbAge.Enabled = True) Then
If (Me.cboAge.Value = "") Then
MsgBox "please fill the form"
End If
End If


If (UserForm1.cbName.Enabled = True Or UserForm1.cbSurname.Enabled = True Or UserForm1.cbGender.Enabled = True Or UserForm1.cbMode.Enabled = True) Then
If Trim(Me.textbox_name.Value = "" Or Me.textbox_surname.Value = "" Or Me.cboGender.Value = "" Or Me.cboMode.Value = "") Then
Me.textbox_name.SetFocus
MsgBox "fill the form"
End If
End If
Exit Sub

'lastcount = Cells(Rows.Count, 1).End(xlUp).Row
'If (Sheet(1).textbox_name.Text = "" Or Sheet(1).textbox_surname.Text = "" Or Sheet(1).textbox_age.Text = "" Or Sheet(1).textbox_gender.Text = "") Then
'MsgBox "???? ??? ?? ???? ??????"
'End If
'Cells(lastcount + 1, 1) = Sheets(1).textbox_name.Text
'Cells(lastcount + 1, 1) = Sheets(1).textbox_surname.Text
'Cells(lastcount + 1, 1) = Sheets(1).textbox_age.Text
'Cells(lastcount + 1, 1) = Sheets(1).textbox_gender.Text


' æÇÑÏ ˜ÑÏä ÇØáÇÚÇÊ ÏÑ �Çí�Çå ÏÇÏå Çí
ws.Cells(iRow, 1).Value = Me.textbox_name.Value
ws.Cells(iRow, 2).Value = Me.textbox_surname.Value
ws.Cells(iRow, 3).Value = Me.cboAge.Value
ws.Cells(iRow, 4).Value = Me.cboGender.Value
ws.Cells(iRow, 5).Value = Me.cboMode.Value


MsgBox "Data added", vbOKOnly + vbInformation, "Data Added"
'ÏÇÏå åÇí ÞÈáí ÑÇ �ǘ ãí ˜äÏ
Me.textbox_name.Value = ""
Me.textbox_surname.Value = ""
Me.cboAge.Value = ""
Me.cboGender.Value = ""
Me.cboMode.Value = ""
Me.textbox_name.SetFocus


End Sub




Private Sub cmdbutton_close_Click()
Unload Me
End Sub






'Private Sub sbAge_SpinDown()
'On Error Resume Next
'Me.textbox_age = Me.textbox_age - 1
'End Sub


'Private Sub sbAge_SpinUp()
'On Error Resume Next
'Me.textbox_age = Me.textbox_age + 1
'End Sub




Private Sub UserForm_Initialize()
Dim cMode As Range
Dim cGender As Range
Dim cAge As Range
Dim ws As Worksheet
Set ws = Worksheets("Sheet1")


For Each cGender In ws.Range("GenderList")
With Me.cboGender
.AddItem cGender.Value
End With
Next cGender


For Each cMode In ws.Range("ModeList")
With Me.cboMode
.AddItem cMode.Value
End With
Next cMode


For Each cAge In ws.Range("AgeList")
With Me.cboAge
.AddItem cAge.Value
End With
Next cAge


End Sub
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Hi & welcome to the board.
What exactly is your question?
All you have done is pasted a load of code, without saying anything.
Also when posting code please use code tags (the # icon)
 
Upvote 0
thanks to you
i wanted to use checkboxes to enable or disable textbox or combobox, so i wrote the code but when running the code its just doesnt do what i want. i think that the if conditions that i defined has got some problems but i cant handle it cause when i want to disable a textbox and dont use of that, again i face with the msgbox saying that fill the form
 
Upvote 0
You can get rid of all your checkbox click events and replace this
Code:
check for a name number
If (UserForm1.cbAge.Enabled = True) Then
If (Me.cboAge.Value = "") Then
MsgBox "please fill the form"
End If
End If
with
Code:
    If Me.[COLOR=#ff0000]CheckBox1 [/COLOR]And Me.[COLOR=#ff0000]ComboBox1[/COLOR].Value = "" Then
        MsgBox "Please fill the form"
    End If
Changing the names in red to match your names.
If the checkbox is ticked, then the combobox must have a value.
If you want it the other way, let me know
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,190
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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