I am entirely new and have very basic knowledge of vb excel. With the help of example given at internet, I have made an application in vb excel. I have used many combo boxes. For example combobox1 is for name of employees, combobox 2 is for "Name of destination" and so on. I have separate excel sheet for each combobox from where I want that for each combo box the value/text be fetched from the relevant excel sheet. I have used the following codes for entire application.
Private Sub ComboBox1_Change()
End Sub
Private Sub CommandButton3_Click()
Unload Me
End Sub
Private Sub CommandButton2_Click()
Call UserForm_Initialize
End Sub
Private Sub DTPicker1_CallbackKeyDown(ByVal KeyCode As Integer, ByVal Shift As Integer, ByVal CallbackField As String, CallbackDate As Date)
End Sub
Private Sub CommandButton1_Click()
Dim RowCount As Long
Dim ctl As Control
' Check user input
If Me.ComboBox1.Value = "" Then
MsgBox "Please choose Executive's Name.", vbExclamation, "Station Leave Application"
Me.ComboBox1.SetFocus
Exit Sub
End If
If Me.ComboBox2.Value = "" Then
MsgBox "Please choose Your Designation", vbExclamation, "Station Leave Application"
Me.ComboBox1.SetFocus
Exit Sub
End If
If Me.ComboBox3.Value = "" Then
MsgBox "Please choose Your Employee No.", vbExclamation, "Station Leave Application"
Me.ComboBox1.SetFocus
Exit Sub
End If
If Me.ComboBox4.Value = "" Then
MsgBox "Please choose Name of your Division", vbExclamation, "Station Leave Application"
Me.ComboBox1.SetFocus
Exit Sub
End If
If Me.ComboBox5.Value = "" Then
MsgBox "Please choose Name of your Reporting Officer", vbExclamation, "Station Leave Application"
Me.ComboBox1.SetFocus
Exit Sub
End If
If Me.DTPicker1.Value = "" Then
MsgBox "Please enter a Date.", vbExclamation, "Station Leave Application"
Me.ComboBox1.SetFocus
Exit Sub
End If
If Me.TextBox1.Value = "" Then
MsgBox "Please Enter Time in HH:MM", vbExclamation, "Station Leave Application"
Me.ComboBox1.SetFocus
Exit Sub
End If
If Me.ComboBox6.Value = "" Then
MsgBox "Please choose AM/PM", vbExclamation, "Station Leave Application"
Me.ComboBox1.SetFocus
Exit Sub
End If
If Me.ComboBox7.Value = "" Then
MsgBox "Please enter Destination", vbExclamation, "Station Leave Application"
Me.ComboBox1.SetFocus
Exit Sub
End If
If Me.DTPicker2.Value = "" Then
MsgBox "Please enter a Date.", vbExclamation, "Station Leave Application"
Me.ComboBox1.SetFocus
Exit Sub
End If
If Me.TextBox2.Value = "" Then
MsgBox "Please Enter Time in HH:MM", vbExclamation, "Station Leave Application"
Me.ComboBox1.SetFocus
Exit Sub
End If
If Me.ComboBox8.Value = "" Then
MsgBox "Please choose AM/PM", vbExclamation, "Station Leave Application"
Me.ComboBox1.SetFocus
Exit Sub
End If
If Me.ComboBox9.Value = "" Then
MsgBox "Please enter reason of station leave", vbExclamation, "Station Leave Application"
Me.ComboBox1.SetFocus
Exit Sub
End If
If Me.ComboBox10.Value = "" Then
MsgBox "Please enter recommedation comment", vbExclamation, "Station Leave Application"
Me.ComboBox1.SetFocus
Exit Sub
End If
'transfer to spreadsheet
Worksheets("Station Leave Application").Select
'go to first blank cell
Cells.Range("B4").Select
ActiveCell.Offset(0, 0).Select
ActiveCell.Value = Me.ComboBox1.Value
ActiveCell.Offset(0, 0).Value = Me.ComboBox1.Value
ActiveCell.Offset(1, 0).Value = Me.ComboBox2.Value
ActiveCell.Offset(2, 0).Value = Me.ComboBox3.Value
ActiveCell.Offset(3, 0).Value = Me.ComboBox4.Value
ActiveCell.Offset(4, 0).Value = Me.ComboBox5.Value
ActiveCell.Offset(5, 0).Value = DateValue(Me.DTPicker1.Value)
ActiveCell.Offset(5, 1).Value = Me.TextBox1.Value
ActiveCell.Offset(5, 2).Value = Me.ComboBox6.Value
ActiveCell.Offset(6, 0).Value = Me.ComboBox7.Value
ActiveCell.Offset(7, 0).Value = DateValue(Me.DTPicker2.Value)
ActiveCell.Offset(7, 1).Value = Me.TextBox2.Value
ActiveCell.Offset(7, 2).Value = Me.ComboBox8.Value
ActiveCell.Offset(8, 0).Value = Me.ComboBox9.Value
ActiveCell.Offset(14, 0).Value = Me.ComboBox10.Value
'hide form
Unload Me
End Sub
Private Sub Label10_Click()
End Sub
Private Sub TextBox1_Change()
End Sub
Private Sub UserForm_Initialize()
'Empty TextBox1
TextBox1.Value = ""
'Empty TextBox2
TextBox2.Value = ""
'Empty ComboBox1
ComboBox1.Clear
'Fill ComboBox1
With ComboBox1
.AddItem "---Select---" (I do not want to add so many names here, instead I want to use an excel sheet where all
such names have been kept. When I click ombobox1 in the application all names of this list
should appeared in the drop down list and I should be able to pick anyone from this list.)
.AddItem "VIRENDER SALMAN, C.E.(Dam)"
.AddItem "M K GOEL, C.E.(HQ)"
.AddItem "D C TRIPATHI, Chief (Geo)"
.AddItem "K K SRIVASTAVA, C.E.(PH)"
.AddItem "DURGESH KUMAR, SM(IT&C)"
.AddItem "SURENDRA JOSHI, Manager(Civil)"
.AddItem " N.M.GUPTA, Manager(M) "
.AddItem "DEEPAK SANADHYA, D.M.(C)"
.AddItem "JAYANTI MALLA PESHIN, D.M.(IT)"
.AddItem "SANJAY PRATAP VIKRAM, A.M.(Civil)"
End With
'Empty ComboBox2
ComboBox2.Clear
'Fill ComboBox2
With ComboBox2
.AddItem "---Select---"
End With
'Empty ComboBox3
ComboBox3.Clear
'Fill ComboBox3
With ComboBox3
.AddItem "---Select---"
End With
'Empty ComboBox4
ComboBox4.Clear
'Fill ComboBox4
With ComboBox4
.AddItem "---Select---"
.AddItem "Civil"
.AddItem "Electrical"
.AddItem "Mechanical"
.AddItem "Finance"
.AddItem "Stores & Disposal"
.AddItem "HR"
.AddItem "Environment"
.AddItem "CE Office"
.AddItem "Electrical & Stores"
.AddItem "IT"
.AddItem "IT & Communication"
.AddItem "Electrical & Communication"
.AddItem "Library"
.AddItem "Hindi"
.AddItem "Medical"
.AddItem "Township"
.AddItem "Water Supply"
.AddItem "Proc & contract"
.AddItem "Planning"
.AddItem "QC &A"
.AddItem "CED"
End With
'Empty ComboBox5
ComboBox5.Clear
'Fill ComboBox5
With ComboBox5
.AddItem "---Select---"
End With
'Empty ComboBox6
ComboBox6.Clear
'Fill ComboBox6
With ComboBox6
.AddItem "---Select---"
.AddItem "AM"
.AddItem "PM"
End With
'Empty ComboBox7
ComboBox7.Clear
'Fill ComboBox7
With ComboBox7
.AddItem "---Select---"
End With
'Empty ComboBox8
ComboBox8.Clear
'Fill ComboBox8
With ComboBox8
.AddItem "---Select---"
.AddItem "AM"
.AddItem "PM"
End With
'Empty ComboBox9
ComboBox9.Clear
'Fill ComboBox9
With ComboBox9
.AddItem "---Select---"
End With
'Empty ComboBox10
ComboBox10.Clear
'Fill ComboBox10
With ComboBox10
.AddItem "---Select---"
.AddItem "Station leave granted"
.AddItem "Recommeded for grant of station leave"
.AddItem "Station leave not granted"
.AddItem "Station leave can not be reommended"
End With
End Sub
Private Sub UserForm_Click()
End Sub
To make you understand my problem I am attaching the application. Kindly guide me how to do the necessary corrections in my application.
Regards
N.M.GUPTA
Bookmarks