Mythri Hegde
New Member
- Joined
- Apr 20, 2011
- Messages
- 11
Hi All,
I have created a form and it is working fine. Here is my form
Private Sub cmdAdd_Click()
Dim iRow As Long
Dim iAction As Long
Dim iPriority As Long
Dim ws As Worksheet
Set ws = Worksheets("PlanningActions")
'find first empty row in database
iRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row
'check for a part number
If Trim(Me.txtAction.Value) = "" Then
Me.txtAction.SetFocus
MsgBox "Please enter an Action"
Exit Sub
End If
'copy the data to the database
ws.Cells(iRow, 1).Value = Me.txtAction.Value
ws.Cells(iRow, 2).Value = Me.txtTopic.Value
ws.Cells(iRow, 3).Value = Me.txtPerson.Value
ws.Cells(iRow, 4).Value = Me.txtLocation.Value
ws.Cells(iRow, 5).Value = Me.txtDate.Value
ws.Cells(iRow, 6).Value = Me.txtContact.Value
ws.Cells(iRow, 7).Value = Me.cboPriority.Value
ws.Cells(iRow, 8).Value = Me.cboPriority.List(iPriority, 1)
'clear the data
Me.txtAction.Value = ""
Me.txtTopic.Value = ""
Me.txtPerson.Value = ""
Me.txtLocation.Value = ""
Me.txtDate.Value = ""
Me.txtContact.Value = ""
Me.cboPriority.Value = ""
Me.txtAction.SetFocus
End Sub
Private Sub cmdClose_Click()
Unload Me
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, _
CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Cancel = True
MsgBox "Please use the button!"
End If
End Sub
Private Sub UserForm_Initialize()
Dim cPri As Range
Dim cLoc As Range
Dim ws As Worksheet
Set ws = Worksheets("LookupLists")
For Each cPri In ws.Range("Priority")
With Me.cboPriority
.AddItem cPri.Value
.List(.ListCount - 1, 0) = cPri.Offset(0, 1).Value
End With
Next cPri
Me.txtAction.Value = ""
Me.txtTopic.Value = ""
Me.txtPerson.Value = ""
Me.txtLocation.Value = ""
Me.txtDate.Value = ""
Me.txtContact.Value = ""
Me.cboPriority.Value = ""
Me.txtAction.SetFocus
End Sub
In my excelsheet already unique ID's of the person has been entered. when the data is entered through this form it should search that particular ID and infront of that data to be entered.
How do i do that?
Thanks in advance
I have created a form and it is working fine. Here is my form
Private Sub cmdAdd_Click()
Dim iRow As Long
Dim iAction As Long
Dim iPriority As Long
Dim ws As Worksheet
Set ws = Worksheets("PlanningActions")
'find first empty row in database
iRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row
'check for a part number
If Trim(Me.txtAction.Value) = "" Then
Me.txtAction.SetFocus
MsgBox "Please enter an Action"
Exit Sub
End If
'copy the data to the database
ws.Cells(iRow, 1).Value = Me.txtAction.Value
ws.Cells(iRow, 2).Value = Me.txtTopic.Value
ws.Cells(iRow, 3).Value = Me.txtPerson.Value
ws.Cells(iRow, 4).Value = Me.txtLocation.Value
ws.Cells(iRow, 5).Value = Me.txtDate.Value
ws.Cells(iRow, 6).Value = Me.txtContact.Value
ws.Cells(iRow, 7).Value = Me.cboPriority.Value
ws.Cells(iRow, 8).Value = Me.cboPriority.List(iPriority, 1)
'clear the data
Me.txtAction.Value = ""
Me.txtTopic.Value = ""
Me.txtPerson.Value = ""
Me.txtLocation.Value = ""
Me.txtDate.Value = ""
Me.txtContact.Value = ""
Me.cboPriority.Value = ""
Me.txtAction.SetFocus
End Sub
Private Sub cmdClose_Click()
Unload Me
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, _
CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Cancel = True
MsgBox "Please use the button!"
End If
End Sub
Private Sub UserForm_Initialize()
Dim cPri As Range
Dim cLoc As Range
Dim ws As Worksheet
Set ws = Worksheets("LookupLists")
For Each cPri In ws.Range("Priority")
With Me.cboPriority
.AddItem cPri.Value
.List(.ListCount - 1, 0) = cPri.Offset(0, 1).Value
End With
Next cPri
Me.txtAction.Value = ""
Me.txtTopic.Value = ""
Me.txtPerson.Value = ""
Me.txtLocation.Value = ""
Me.txtDate.Value = ""
Me.txtContact.Value = ""
Me.cboPriority.Value = ""
Me.txtAction.SetFocus
End Sub
In my excelsheet already unique ID's of the person has been entered. when the data is entered through this form it should search that particular ID and infront of that data to be entered.
How do i do that?
Thanks in advance