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
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