Function which changes data entered in TextBox into a number format.
Answers
Answer:
Private Sub Add_Eval_Add_Click()
Dim iCol As Long
Dim ws As Worksheet
Set ws = Worksheets("Gradebook")
'find first empty column in database
iCol = ws.Cells.Find(What:="*", SearchOrder:=xlColumns, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Column + 1
'check for an evaluation title
If Trim(Me.Eval_Title.Value) = "" Then
Me.Eval_Title.SetFocus
MsgBox "Please enter an evaluation title."
Exit Sub
End If
'check for a category
If Trim(Me.Eval_Cat.Value) = "" Then
Me.Eval_Cat.SetFocus
MsgBox "Please choose a category."
Exit Sub
End If
'check for an assigned date
If Trim(Me.Eval_Date.Value) = "" Then
Me.Eval_Date.SetFocus
MsgBox "Please enter the date the evaluation was assigned."
Exit Sub
End If
'check for a due date
If Trim(Me.Eval_Due_Date.Value) = "" Then
Me.Eval_Due_Date.SetFocus
MsgBox "Please enter the due date."
Exit Sub
End If
'check for a points value
If Trim(Me.Eval_Points.Value) = "" Then
Me.Eval_Points.SetFocus
MsgBox "Please enter the available points."
Exit Sub
End If
'copy the data to the database
'use protect and unprotect lines,
' with your password
' if worksheet is protected
With ws
' .Unprotect Password:="password"
.Cells(1, iCol).Value = Me.Eval_Title.Value
.Cells(2, iCol).Value = Me.Eval_Cat.Value
.Cells(3, iCol).Value = Me.Eval_Date.Value
.Cells(4, iCol).Value = Me.Eval_Due_Date.Value
.Cells(5, iCol).Value = Me.Eval_Points.Value
' .Protect Password:="password"
End With
'clear the data
Me.Eval_Title.Value = ""
Me.Eval_Cat.Value = ""
Me.Eval_Date.Value = ""
Me.Eval_Due_Date.Value = ""
Me.Eval_Points.Value = ""
Me.Eval_Title.SetFocus
End Sub