Private Sub cmdAdd_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("LogFile")
'find first empty row in database
iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
'copy the data to the database
ws.Cells(iRow, 1).Value = Me.cboMethod.Value
ws.Cells(iRow, 2).Value = Me.txtDate.Value
ws.Cells(iRow, 3).Value = Me.cboStore.Value
ws.Cells(iRow, 4).Value = Me.cboName.Value
ws.Cells(iRow, 5).Value = Me.cboSubject.Value
ws.Cells(iRow, 6).Value = Me.txtContact.Value
ws.Cells(iRow, 7).Value = Me.txtCompany.Value
ws.Cells(iRow, 8).Value = Me.txtDetails.Value
ws.Cells(iRow, 9).Value = Me.txtNextAction.Value
ws.Cells(iRow, 10).Value = Me.txtFollowDue.Value
ws.Cells(iRow, 11).Value = Me.cboStatus.Value
ws.Cells(iRow, 12).Value = Me.txtUser.Value
'clear the data
Me.cboMethod.Value = ""
Me.txtDate.Value = ""
Me.cboStore.Value = ""
Me.cboName.Value = ""
Me.cboSubject.Value = ""
Me.txtContact.Value = ""
Me.txtCompany.Value = ""
Me.txtDetails.Value = ""
Me.txtNextAction.Value = ""
Me.txtFollowDue.Value = ""
Me.cboStatus.Value = ""
Me.txtUser.Value = ""
Me.cboMethod.SetFocus
Me.txtDate = Format(Date, "mm/dd/yyyy")
Me.txtUser = Environ$("USERNAME")
End Sub
Private Sub CommandButton1_Click()
LastRow = FindLastRow - 1
RowNumber.Text = FormatNumber(LastRow, 0)
End Sub
Private Sub CommandButton10_Click()
ClearFilter
End Sub
Private Sub CommandButton11_Click()
If ActiveSheet.FilterMode Then
ActiveSheet.ShowAllData
End If
End Sub
Private Sub CommandButton12_Click()
Unload Me
End Sub
Private Sub CommandButton2_Click()
Dim r As Long
Sheets("LogFile").Select
If RowNumber > 2 Then
r = RowNumber.Value + 1
RowNumber.Value = r
Else
If RowNumber < 3 Then
MsgBox "Illegal row number"
ClearData
Else
If RowNumber > LastRow Then
MsgBox "Illegal row number"
ClearData
End If
End If
End If
EnableSave
End Sub
Private Sub CommandButton4_Click()
Dim r As Long
Sheets("LogFile").Select
If RowNumber > 3 Then
r = RowNumber.Value - 1
RowNumber.Value = r
Else
If RowNumber < 3 Then
MsgBox "Illegal row number"
ClearData
Else
If RowNumber > LastRow Then
MsgBox "Illegal row number"
ClearData
End If
End If
End If
EnableSave
End Sub
Private Sub CommandButton7_Click()
PutData
End Sub
Private Sub CommandButton8_Click()
ClearData
Me.cboMethod.SetFocus
End Sub
Private Sub CommandButton9_Click()
With ActiveSheet
.AutoFilterMode = False
With .Range("c3")
.AutoFilter
If Len(Me.cbofilterstore.Value) > 0 Then
.AutoFilter Field:=3, Criteria1:=Me.cbofilterstore.Value
End If
If Len(Me.cbofiltersubject.Value) > 0 Then
.AutoFilter Field:=5, Criteria1:=Me.cbofiltersubject.Value
End If
If Len(Me.cbofilterstatus.Value) > 0 Then
.AutoFilter Field:=11, Criteria1:=Me.cbofilterstatus.Value
End If
If Len(Me.cbofilterdate.Value) > 0 Then
.AutoFilter Field:=2, Criteria1:=Me.cbofilterdate.Value
End If
End With
End With
End Sub
Private Sub ClearFilter()
cbofilterdate = ""
cbofilterstore = ""
cbofiltersubject = ""
cbofiltertatus = ""
End Sub
Private Sub txtDate_Change()
End Sub
Private Sub cboname_Change()
End Sub
Private Sub UserForm_Initialize()
Dim cLoc As Range
Dim ws As Worksheet
Set ws = Worksheets("LookupLists")
Me.cboMethod.SetFocus
For Each cLoc In ws.Range("Method")
With Me.cboMethod
.AddItem cLoc.Value
End With
Next cLoc
For Each cLoc In ws.Range("Categories")
With Me.cboSubject
.AddItem cLoc.Value
End With
Next cLoc
For Each cLoc In ws.Range("Status")
With Me.cboStatus
.AddItem cLoc.Value
End With
Next cLoc
For Each cLoc In ws.Range("Stores")
With Me.cboStore
.AddItem cLoc.Value
End With
Next cLoc
For Each cLoc In ws.Range("Stores")
With Me.cbofilterstore
.AddItem cLoc.Value
End With
Next cLoc
For Each cLoc In ws.Range("Categories")
With Me.cbofiltersubject
.AddItem cLoc.Value
End With
Next cLoc
For Each cLoc In ws.Range("Status")
With Me.cbofilterstatus
.AddItem cLoc.Value
End With
Next cLoc
For Each cLoc In ws.Range("date")
With Me.cbofilterdate
.AddItem cLoc.Value
End With
Next cLoc
For Each cLoc In ws.Range("Name")
With Me.cboName
.AddItem cLoc.Value
End With
Next cLoc
Me.txtDate = Format(Date, "mm/dd/yyyy")
Me.txtUser = Environ$("USERNAME")
End Sub
Private Sub cmdClose_Click()
Unload Me
End Sub
Private Sub GetData()
Dim r As Long
LastRow = FindLastRow
If IsNumeric(RowNumber.Text) Then
r = CLng(RowNumber.Text)
Else
ClearData
MsgBox "Illegal row number"
Exit Sub
End If
If r > 0 And r <= LastRow Then
cboMethod = Cells(r, 1)
txtDate = Cells(r, 2)
txtStore = Cells(r, 3)
cboName = Cells(r, 4)
cboSubject = Cells(r, 5)
txtContact = Cells(r, 6)
txtCompany = Cells(r, 7)
txtDetails = Cells(r, 8)
txtNextAction = Cells(r, 9)
txtFollowDue = Cells(r, 10)
cboStatus = Cells(r, 11)
txtUser = Cells(r, 12)
ElseIf r = 0 Then
ClearData
Else
ClearData
MsgBox "Invalid row number"
End If
DisableSave
End Sub
Private Sub ClearData()
cboMethod = ""
txtDate = ""
txtStore = ""
cboName = ""
cboSubject = ""
txtContact = ""
txtCompany = ""
txtDetails = ""
txtNextAction = ""
txtFollowDue = ""
cboStatus = ""
txtUser = ""
End Sub
Private Sub RowNumber_Change()
GetData
End Sub
Private Function FindLastRow()
Dim r As Long
r = 3
Do While r < 65536 And Len(Cells(r, 1).Text) > 0
r = r + 1
Loop
FindLastRow = r
End Function
Private Sub PutData()
Dim r As Long
LastRow = FindLastRow
If IsNumeric(RowNumber.Text) Then
r = CLng(RowNumber.Text)
Else
MsgBox "Illegal row number"
End If
If r > 1 And r <= LastRow Then
Cells(r, 1) = cboMethod
Cells(r, 2) = txtDate
Cells(r, 3) = txtStore
Cells(r, 4) = cboName
Cells(r, 5) = cboSubject
Cells(r, 6) = txtContact
Cells(r, 7) = txtCompany
Cells(r, 8) = txtDetails
Cells(r, 9) = txtNextAction
Cells(r, 10) = txtFollowDue
Cells(r, 11) = cboStatus
Cells(r, 12) = txtUser
DisableSave
Else
MsgBox "Illegal row number"
End If
End Sub
Private Sub DisableSave()
CommandButton7.Enabled = False
CommandButton6.Enabled = False
End Sub
Private Sub EnableSave()
CommandButton7.Enabled = True
CommandButton6.Enabled = True
End Sub
Bookmarks